在models.py
中class Activities(models.Model):
day = models.PositiveIntegerField(default=1, null=False,blank=False,db_index=True)
activity = models.CharField(max_length=100, blank=False,choices=activity_choices, db_index=True)
description = models.TextField(null=True,blank=True)
sequence = models.PositiveIntegerField(null=True,blank=True)
class holidaygroup(models.Model):
....
activity = generic.GenericRelation(Activities)
在admin.py
中class ActivitiesInline(generic.GenericTabularInline):
model = Activities
class holidaygroupAdmin(ReadOnlyAdminFields,admin.ModelAdmin):
....
inlines = [SeasonalPriceInline,ImageInline,HotelsInline,seoInline,NotesInline,ActivitiesInline,]
当我试图运行服务器时出现以下错误
ERRORS:
<class 'holidays.admin.ActivitiesInline'>: (admin.E301) 'holidays.Activities' has no GenericForeignKey.
提前致谢
答案 0 :(得分:1)
您当前的模型结构是每个活动下您有零个或多个假日组。如果您尝试将多个Activities
存储在一个holidaygroup
下,则应在Activities
模型中使用外键:
class holidaygroup(models.Model):
...
class Activities(models.Model):
...
holiday_group = models.ForeignKey(holidaygroup)
这样,每个Activities
下都可以有一个holidaygroup
内联列表。