我对Django-Admin
有点问题。所以我有一个模型UserProfile
,它扩展了一个regulear User
。还有其他模型:Language
,Level
和UserProfileLanguage
这是一个直通模型。
class UserProfileLanguage(models.Model):
userprofile = models.ForeignKey(UserProfile)
language = models.ForeignKey(Language)
level = models.ForeignKey(Level)
class Meta:
unique_together = (('userprofile', 'language'),)
问题是我无法在languages
的{{1}}标签中看到属性User
:
Django-Admin
所以我决定将其明确地放在class UserProfile(...
...
languages = models.ManyToManyField(Language, through='UserProfileLanguage')
标签中,以便User
:
admin.py
CMD说:
from django.contrib import admin
from models import *
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
admin.site.register(AdminContact)
class UserProfileInline(admin.StackedInline):
model = UserProfile
can_delete = False
verbose_name_plural = 'User_Profile'
# this does not work
class UserProfileLanguageLevelInline(admin.StackedInline):
model = UserProfileLanguage
class UserAdmin(BaseUserAdmin):
inlines = (UserProfileInline,UserProfileLanguageLevelInline, )
admin.site.unregister(User)
admin.site.register(User,UserAdmin)
admin.site.register(LanguageTuple)
admin.site.register(Language)
admin.site.register(Job)
admin.site.register(UserProfileLanguage)
问题在于ERRORS:
<class 'SolutionsForLanguagesApp.admin.UserProfileLanguageLevelInline'>: (admin.
E202) 'SolutionsForLanguagesApp.UserProfileLanguage' has no ForeignKey to 'auth.
User'.
与UserProfileLanguage
和UserProfile
与UserProfile
相关联。你知道该怎么办吗?