Reputation: 392
How can i use uppercase characters when adding a property with lowercase choices
this is the payload im using Clover is capitalized but i want to know how i can have capitalized and lowercase Clover work at the same time using model_utils Choices
"name": "Test",
"pos_name": "Clover",
class Tenant(TimeStampedModel):
POS = Choices('square', 'clover', 'omnivore')
pos_name = models.CharField(choices=POS, max_length=50, blank=True, default='')
name = models.CharField(max_length=100)
Upvotes: 2
Views: 461
Reputation: 3957
Maybe by overriding model's __setattr__?
def __setattr__(self, attr, value):
if attr == "pos_name":
value = value.lower()
super().__setattr__(attr, value)
Upvotes: 1