0

I am creating custom user model in django administration. I would like to implement field of id in window where you can add a new users. I use "add_fieldsets()" in order to adding new additional fields to it . But it is possible inserting default elements : 'email', 'username', 'password1','is_staff','is_active','last_login','first_name','date_joined'.This tutorial shows how to create it with default fields :

https://testdriven.io/blog/django-custom-user-model/

How can I implement custom field in add_fieldsets() ? Is it possible ?

Here is my code :

python

: admin.py

class CustomUserAdmin(UserAdmin):  
    list_display = ('username', 'email', 'first_name', 'last_name', 'id')
    list_select_related = ('profile', )
    add_fieldsets = (
    (None, {
        'classes': ('wide',),
        'fields': ('email', 'username', 'password1','is_staff', 'is_active','last_login','first_name','date_joined')
    }),
    )
    def get_inline_instances(self, request, obj = None):
        if not obj:
            return list()
        return super(CustomUserAdmin, self).get_inline_instances(request, obj)

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

For example it looks something like that :

Example picture

add_fieldsets = (
    (None, {
        'classes': ('wide',),
        'fields': ('username', 'password1','id')
    }),
    )
mactka
  • 1
  • 1
  • Are you asking how you can add custom fields to the `User` model and extend it? If so, have a look at [this post](https://stackoverflow.com/q/44109/9374673) which deals with that topic. If not, please clarify what you mean by "How can I implement own field?" – Mihai Chelaru Dec 17 '19 at 13:31
  • Please tell us what you mean by "own field" by telling us specifically what you're trying to add. Give us an example. – dirkgroten Dec 17 '19 at 13:35
  • Thank you for your replay . Possibly I wrote not precise question . I can add default fields such as 'email', 'username', 'password1','is_staff', 'is_active','last_login','first_name','date_joined' to add_fieldsets() . This variable adds fields to window where you can add new user . I would like to insert number of id when I am adding a new users . – mactka Dec 17 '19 at 13:49
  • I edited my question above . – mactka Dec 17 '19 at 14:04

0 Answers0