first of all you need unregister default django models and then register yours 
AdminModel like:
admin.site.unregister(User)
admin.site.register(User, CustomUserAdmin)


пятница, 26 июня 2015 г., 3:16:24 UTC+3 пользователь Henri написал:
>
> I'm using a custom user model and a custom UserAdmin.
> I try do overwrite the 'get_fieldsets' method to change some fields and 
> hide some others, bud django admin still uses the  'get_fieldsets' method 
> from django.contrib.auth.admin.UserAdmin.
>
> My CustomUserAdmin Class:
>
> from django.contrib.auth.admin import UserAdmin
> from users.models import User  # custom user model
>
>
> class CustomUserAdmin(UserAdmin):
>
>     add_fieldsets = (
>         (None, {
>             'classes': ('wide',),
>             'fields': ('email', 'username', 'password1', 'password2')
>         }),
>     )
>
>     # The forms to add and change user instances
>     form = UserChangeForm
>     add_form = UserCreationForm
>
>     # The fields to be used in displaying the User model.
>     # These override the definitions on the base UserAdmin
>     # that reference specific fields on auth.User.
>     list_display = ('email', 'username', 'first_name', 'last_name', 
> 'is_active', 'is_staff',
>                     'is_superuser')
>     list_filter = ('is_active', 'is_staff', 'is_superuser')
>     search_fields = ('email', 'first_name', 'last_name', 'username')
>     ordering = ('email',)
>     filter_horizontal = ('groups', 'user_permissions',)
>
>
>     def get_fieldsets(self, request, obj=None):
>         if not obj:
>             return self.add_fieldsets
>
>         if request.user.is_superuser and request.user.pk != obj.pk:
>             perm_fields = ('is_active', 'is_staff', 'is_superuser',
>                            'groups', 'user_permissions')
>         else:
>             perm_fields = ('is_active', 'is_staff', 'groups')
>
>         return [(None, {'fields': ('email', 'password')}),
>                 (_('Personal info'), {'fields': ('first_name', 'last_name'
> , 'username', 'biography')}),
>                 (_('Permissions'), {'fields': perm_fields}),
>                 (_('Important dates'), {'fields': ('last_login', 
> 'date_joined')})]
>
>
> admin.site.register(User, CustomUserAdmin)
>
>
>
>
> Some body have an idea, whats going on?
> I'm working on this for days.
> Please help.
>

-- 
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 [email protected].
To post to this group, send email to [email protected].
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/3ded59f3-df1f-40f5-97f8-365c40d681e1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to