开发者

Django inlinemodeladmin extra option not working

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.

Here is the code:

#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')
    exc开发者_运维百科lude = ('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)

This is the relevant spot in the django docs: https://docs.djangoproject.com/en/1.3/ref/contrib/admin/#inlinemodeladmin-options

Thanks!


Did you try setting max_num to 1 as well?

If the value of max_num is greater than the number of existing related objects, up to extra additional blank forms will be added to the formset, so long as the total number of forms does not exceed max_num

This from the docs about model formsets, but it should work for the InlineAdmin as well.


Ok, I've figured it out now. Bit of a silly mistake really.

I upgraded my django version a while ago, but I forgot to update the django admin media files.

When I checked my apache log, I found a few js erorrs relating to inlines.js and a couple of other files.

Updating my admin js files with the ones from the django 1.3 package solved the problem.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜