Django inlinemodeladmin额外的选项不工作 [英] Django inlinemodeladmin extra option not working
问题描述
我正在将用户配置文件内联添加到django admin上的编辑用户页面。到目前为止,唯一的问题是无论我在额外选项中有多少值,页面总是显示1个额外的用户配置文件记录的字段。
我实际上并不想显示任何额外的记录,但是我无法获得额外的记录。希望有人可以帮助,这让我感到困惑。
I'm in the process of adding a user profile inline to the edit user page on django admin. So far the only problem is no matter what value I put in the "extra" option, the page always displays fields for 1 extra user profile record. I don't actually want to display any extra records, but I can't get the extra one to go away. Hopefully someone can help, it has me stumped.
这是代码:
#admin.py
class UserProfileInline(admin.StackedInline):
model = auth_user_profiles
extra = 0
raw_id_fields = ('organisation_id','advertiser_id','division_id','rtp_id','person_id','hp_organisation_id')
exclude = ('specialist_id',)
class UserAdmin(admin.ModelAdmin):
list_display = ('username', 'email', 'first_name', 'last_name', 'is_staff', 'is_active', 'is_superuser', 'last_login', 'date_joined')
list_filter = ('is_staff', 'is_superuser', 'is_active')
search_fields = ('username','email','first_name','last_name')
inlines = (UserProfileInline,)
admin.site.unregister(User)
admin.site.register(User, UserAdmin)
这是相关斑点在django文档: https://docs.djangoproject.com/en/ 1.3 / ref / contrib / admin /#inlinemodeladmin-options
This is the relevant spot in the django docs: https://docs.djangoproject.com/en/1.3/ref/contrib/admin/#inlinemodeladmin-options
谢谢!
推荐答案
好的,我已经弄清楚了。真的有点愚蠢的错误。
Ok, I've figured it out now. Bit of a silly mistake really.
我刚才升级了我的django版本,但我忘了更新django admin媒体文件。
I upgraded my django version a while ago, but I forgot to update the django admin media files.
当我检查了我的apache日志时,我发现了几个关于inlines.js和几个其他文件的js erorrs。
When I checked my apache log, I found a few js erorrs relating to inlines.js and a couple of other files.
使用django 1.3包中的文件更新我的管理员js文件解决了这个问题。
Updating my admin js files with the ones from the django 1.3 package solved the problem.
这篇关于Django inlinemodeladmin额外的选项不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!