In my django model I am trying to set fields like this:
mouth = models.DecimalField(choices=SCALE, max_digits=2, decimal_places=1)
nose = models.DecimalField(choices=SCALE, max_digits=2, decimal_places=1)
persistance = models.DecimalField(choices=SCALE, max_digits=2, decimal_places=1)
rating = models.DecimalField(choices=SCALE, max_digits=2, decimal_places=1)
the choices are defined globally like this:
SCALE = ( (0.5*x, str(0.5*x)) for x in xrange(1,11) )
I register these fields in my admin.py file. The problem I have is that only the first field that is defined (in this case mouth), will display the choices list. The other ones wont display any list at all. The same scenario happens when I create a ModelForm instance and output it into a template: I dont get the list for the other fields.
Also if I try to inverse the order of the fields, It is still the first one that is displayed correctly, so it's not something related to the mouth field itself.
Is there an option I need to pass to make the fields more 'distinct'?
In your definition, SCALE
is a generator expression, not a sequence, so the generator is very probably exhausted after the first iteration (on your first field using it). Try using a list comprehension instead, ie SCALE = [(0.5*x, str(0.5*x)) for x in xrange(1,11)]