Extand Django User model and show this on admin

Extand Django User model and show this on admin

I use the latest django for an intranet project. Well, I followed the django documentation to extend my models:

I use the latest django for an intranet project. Well, I followed the django documentation to extend my models:

from django.db import models
from django.contrib.auth.models import AbstractUser

class Employee(AbstractUser): DEPARTMENTS = ( ('ARE', 'Area Manager'), ('IT', 'IT'), ('CAT', 'Category manager'), ('CON', 'Controling') ) departement = models.CharField(max_length = 3, verbose_name = "DĂ©partement", choices = DEPARTMENTS)

After that, I rewrited the admin.py:

from django.contrib import admin
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
from django.contrib.auth.models import User

from .models import Employee

Define an inline admin descriptor for Employee model

which acts a bit like a singleton

class EmployeeInline(admin.StackedInline): model = Employee can_delete = False verbose_name_plural = 'Employees'

Define a new User admin

class UserAdmin(BaseUserAdmin): inlines = (EmployeeInline,)

Re-register UserAdmin

admin.site.register(User) # return error: django.contrib.admin.sites.NotRegistered: The model User is not registered

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

As you can see on the 3 last line of my admin.py, if I register User model I have an error. If I comment my last lines

# Re-register UserAdmin
#admin.site.unregister(User)
admin.site.register(User, UserAdmin)

I haven't my User administration: 


Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

Python Django Tutorial | Django Course

đŸ”„Intellipaat Django course: https://intellipaat.com/python-django-training/ 👉This Python Django tutorial will help you learn what is django web development &...

Developing Restful APIs with Python, Django and Django Rest Framework

This article is a definitive guide for starters who want to develop projects with RESTful APIs using Python, Django and Django Rest Framework.