湘江地区的连锁涉外关系

2024-05-19 17:02:55 发布

您现在位置:Python中文网/ 问答频道 /正文

新手,我想在Django建立一个简单的涉外关系。 肉——牛肉——营养数据。我一直在犯错误

<class 'foods_data.models.Nutrition_Data'> has no ForeignKey to <class'foods_data.models.Nutrition_Data'>

这是我的模型代码。你知道吗

from django.db import models

# Create your models here.

class Category(models.Model):
    cat_name = models.CharField(max_length = 200)

    def __unicode__(self):
        return self.cat_name

class Food_Item(models.Model):
   category = models.ForeignKey(Category)
   food_name = models.CharField(max_length = 200)

   def __unicode__(self):
        return self.food_name

class Nutrition_Data(models.Model):
   food_item = models.ForeignKey(Food_Item)
   nut_name = models.CharField(max_length = 50)
   nut_amount = models.IntegerField(default=0)

   def __unicode__(self):
        return self.nut_name

Tags: nameselfdatamodelreturnfoodmodelsdef