I'm trying to create a django model using Text as a value for the IntegerField
class User(models.Model):
class UserRole(models.IntegerChoices):
FULLACCESS = 0, _('full_access_user')
READONLY = 1, _('read_only_user')
WRITEONLY = 2, _('write_only_user')
role = models.IntegerField(choices=UserRole.choices)
When I try to create the user like
User.objects.create(role="full_access_user")
it does not map the string value to integer.
Tried to define models.IntegerChoices
as models.TextChoices
and map those to integer but django forbids such action. What could be done to create the object like it's shown in the example ?