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

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -