Declaring Model Value in Django

  django, python

I am pretty new to Django and I cannot figure out how to declare the value of a model.
For example, if I have a CharField that takes the choice of three sizes s, m, l. Then auto-populate the value for length and width. So, it would be something like this.

s = {
"length": 5,
"width": 7
}
m = {
"length": 8,
"width": 10
}
l = {
"length": 12,
"width": 18
}
CHOICE_LIST = [
("s", "Small"),
("m", "Medium"),
("l", "Large")
]
size = models.CharField(choices = CHOICE_LIST)
length = models.IntegerField()
width = models.IntegerField()

Then somehow make the model instances length and width = the dictionary length width based on model instances size. So, if you inputted small it would make length 5 and width 7.

Source: Python Questions

LEAVE A COMMENT