Django Model Charfield many Choices automatically create? -
i want add choices between year 1950 2020. how can that?
a = 1950 while < 2020: b=a + 1 year_choices = ( ('b', 'b'), ) class sezonlar(models.model): sezon = models.charfield(max_length=4, choices=year_choices)
the requirement choices
field just:
an iterable (e.g., list or tuple) of 2-tuples use choices field.
so can construct using list comprehension so:
year_choices = [(str(yr), str(yr)) yr in range(1950, 2020)]
Comments
Post a Comment