It sounds like you don't want to hardcode the possible options (because you used charfield), but at the same time you say that there are a small number of options.
If you are content with a hard code of choice, you can instead change to a whole field:
class Shirt(models.Model): SIZE_CHOICES = ( (1, u'small'), (2, u'medium'), (3, u'large'), (4, u'x-large'), (5, u'xx-large'), ) size = models.IntegerField(choices = SIZE_CHOICES)
If you do not want to hardcode the sizes, then you probably want to move the available sizes to a separate model and refer to it as a foreign key from your Shirt model. To make it an arbitrary sort, you will need an index of some other type besides the primary key, which you can sort. Maybe something like this:
class Size(models.Model): sortorder = models.IntegerField() name = models.CharField() class Meta: ordering = ['sortorder']
Daniel Eriksson
source share