在我的Django应用中,我具有以下models.py:from django.db import modelsimport datetimeclass Job(models.Model): name = models.CharField(max_length = 250, null = False) user = models.CharField(max_length = 30, null = False) command = models.CharField(max_length = 1000, null = False) whenToRun = models.DateTimeField('Run Date', null = False) output = models.CharField(max_length = 100000, null = True)class Host(models.Model): jobs = models.ManyToManyField(Job, blank = True) name = models.CharField(max_length = 100, null = False) hasRun = models.BooleanField(default = False)我在https://docs.djangoproject.com/en/dev/topics/db/examples/many_to_many/的指导下在Host类中添加了作业分配。我可以毫无问题地添加主机(从管理页面),但是当我尝试添加作业时,出现以下错误:Exception at /admin/Minion/job/add<class 'Minion.models.Host'> has no ForeignKey to <class 'Minion.models.Job'>我也尝试向Job类添加ManyToManyField分配,但是它告诉我名称Host是未定义的。有谁知道我该怎么做才能使此字段正常运行?在此先感谢您的帮助。
添加回答
举报
0/150
提交
取消