How can I show besides the columns username, email, first name, last name, staff user a 5th column with the users ID. I think I have to write some code into admin.py like:
class CustomUserAdmin(UserAdmin):
readonly_fields = ('id',)
admin.site.register(CustomUserAdmin)
You should take advantage of ModelAdmin.list_display
, docs here --> https://docs.djangoproject.com/en/2.2/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_display
class CustomUserAdmin(UserAdmin):
list_display = ('username', 'email', 'first_name', 'last_name', 'id')
readonly_fields = ('id',)
admin.site.register(User, CustomUserAdmin)
In case you incur in an AlreadyRegistered
error, you should add the following prior to your admin.site.register
line
admin.site.unregister(User)