I extended the standard user by inheriting from AbstractUser. However I cannot seem to be able to make any changes to the UserForm in the admin. This is what I tried:
class CustomUserChangeForm(UserChangeForm):
class Meta:
model = User
exclude = []
# exclude = ['is_staff']
readonly_fields = ['date_joined']
The field date_joined is not readonly. When I don’t have either fields or exclude in the form, I get an error. But when I put any fields in those lists, I get an error as well. If for instance I put in is_staff as in the outcommented line, I get the error:
“Key ‘is_staff’ not found in ‘UserForm’. Choices are: date_joined, email, first_name, groups, is_active, is_superuser, last_login, last_name, password, user_permissions, username.”
It will always list all the model properties except the one that I put in exclude. Also, all the extra model properties that I added are being ignored.
from django.contrib.auth.models import AbstractUser
from django.db import models as m
class User(AbstractUser):
# user credentials, needed for bills (PDF generator)
business_phone = m.CharField(max_length=256, blank=True) # telephone number for business contacts
# billing_address = m.ForeignKey(Address, on_delete=m.CASCADE)
tax_reference = m.CharField(max_length=256, blank=True) # Steuernummer
# bank account
IBAN = m.CharField(max_length=256, blank=True)
BIC = m.CharField(max_length=256, blank=True)
bank_name = m.CharField(max_length=256, blank=True)