I have a custom user model that includes an account_type
field like this:
class User(AbstractUser):
# ...
account_type = models.CharField(max_length=2, choices=AccountType.choices, default=AccountType.BASIC, null=True)
# ...
I have an AccountType
defined as follows outside the User model:
class AccountType(models.TextChoices):
BASIC = 'BA', 'basic'
STANDARD = 'ST', 'standard'
SUPPORTER = 'SU', 'supporter'
PROFESSIONAL = 'PR', 'professional'
def __str__(self):
return str(self.name)
I can modify this field on a user from the shell using a valid value, i.e. ‘PR’ or AccountType.PROFESSIONAL
and save the user.
The value is saved to the database, however when I refresh the django admin page, it still shows basic.
If I use the django admin page to choose an item from the account_type
field and save it using the Save and Continue Editing Button, the page does correctly set the widget value following the form post. If I refresh, the value is also shown correctly.
If I then check this in my shell, yes, the value was indeed saved to the DB.
If I then manually set the value and user.save()
in the shell, and reload the page, it remains showing the value last submitted.
I’ve tested both the default admin.ModelAdmin
and a version using fieldsets including this field.
I’ve sanity checked this by toggling a boolean field tos_agreement
on the user model and it updates just fine on refresh in admin.
Stumped on this, any ideas?