我有三个模型 - 其中两个在一个应用程序中,第三个在另一个应用程序中。结构是这样的:
taapp.models:
class Teachers(model.Model):
fullname = models.CharField(max_length=50)
...
class TeachersScale(model.Model):
teacher = models.ForeignKey("Teachers")
abbr = models.ForeignKey("questions.QuestionTypes")
问题.模型:
class QuestionTypes(models.Model):
abbr = models.CharField(max_length=5)
......
我将所有这些模型注册到管理员:
taapp.admin:
from taapp.models import Teachers
from taapp.models import TeachersScale
from django.contrib import admin
from admin_forms import TeachersAdmin, TeachersScaleAdmin
admin.site.register(Teachers, TeachersAdmin)
admin.site.register(TeachersScale, TeachersScaleAdmin)
taapp.admin_forms:
from django import forms
from django.contrib import admin
class TeachersAdmin(admin.ModelAdmin):
list_display = ('fullname', 'email', 'registration_date')
class TeachersScaleAdmin(admin.ModelAdmin):
list_display = ('teacher', 'abbr')
list_filter = ['teacher','abbr']
当我尝试TeachersScale
在管理站点中添加字段时,出现以下错误:
DatabaseError at /admin/taapp/teachersscale/add/
(1146, "Table 'taapp.questions_questiontypes' doesn't exist")
它对待QuestionTypes
,因为它是一个模型taapp
。如何解决?还是我的数据库设计有问题?
我试图看看反向添加是否有效TabularInline
。QuestionTypes
好吧,它有效:
问题.admin:
class TeachersScaleInline(admin.TabularInline):
model = TeachersScale
class QuestionTypesAdmin(admin.ModelAdmin):
inlines = [TeachersScaleInline]
提前致谢。