Extened User and have fieldsets instead of inlines

21 views
Skip to first unread message

Elliot

unread,
Aug 13, 2014, 11:57:04 PM8/13/14
to django...@googlegroups.com
Is it possible to have a exteneded user profile in the 'User' part of the admin. I have tried the following with a form (UserProfileForm(forms.ModelForm)) with 2 fields 'something' and 'something else'

class UserAdminCustom(UserAdmin):
    form = UserProfileForm
     fieldsets = (
         (None, {'fields': ('username', 'password', 'something', 'something_else')}),
         ('Personal info', {'fields': ('first_name', 'last_name', 'email')}),
         ('Permissions', {'fields': ('is_staff', 'is_active', 'is_superuser', 'user_permissions')}),
         ('Important dates', {'fields': ('last_login', 'date_joined')}),
         ('Groups', {'fields': ('groups',)}),
     )
    

admin.site.unregister(User)
admin.site.register(User, UserAdminCustom)

What it results in is the 2 new fields as expected in the User in admin but the fields are empty and it saves nothing to these fields on save. 

Is the only option to use inlines, like below, or am I just missing something.

class UserProfile2Inline(admin.StackedInline):
    model = UserProfile2

class UserAdminCustom(UserAdmin):
    inlines = (UserProfile2Inline,)

admin.site.unregister(User)
admin.site.register(User, UserAdminCustom)

Cheers if someone can shed some light on this for me.

Elliot

Andrea

unread,
Aug 14, 2014, 7:06:57 AM8/14/14
to django...@googlegroups.com
I've personally used your approach with the following Inline:


class UserProfile2Inline(admin.StackedInline):
    model = UserProfile2
    can_delete = False
    fk_name = 'user'   
    max_num = 1

Andrea



Elliot

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/825615e1-e364-4a60-94de-e7abde68b409%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Elliot

unread,
Aug 15, 2014, 8:46:09 PM8/15/14
to django...@googlegroups.com
Thanks Andrea,

I was more looking to see if anyone had used fieldsets instead of inlines. I imagine it would be quite possible with rewriting the view that serves up the change form for user. It just seems that the fieldset gets rendered because of the associated form but then isn't actually related to the model. Hence the empty fields and not saving the values. 

Collin Anderson

unread,
Aug 16, 2014, 5:51:48 PM8/16/14
to django...@googlegroups.com
Can you make your UserProfile2 a subclass of UserProfile?
Reply all
Reply to author
Forward
0 new messages