The last I heard, choices only worked for CharFields. Probably it is trying to compare 600.0 with '600.0' and failing, so it resorts to the unmatched "-----", or failing to save the value properly in the first place. Docs don't clarify, though - it might have changed recently. If so, your best bet (if possible) is to use a char field representing that value & convert it later on. What I have done in those cases is to use a dict to hold all the values & generate tuples from that dict.
-rob On Apr 23, 5:16 am, "Hancock, David (DHANCOCK)" <[EMAIL PROTECTED]> wrote: > Django-0.96. I've discovered the get_FOO_display() function that I get for > free when I use a "choices=CHOICES" in a model, and I understand how to use > it in a template or in the API. But the problem I'm having is that when I > save something with a choices attribute, editing that object subsequently > shows the item as "---------" (as if it's never been set before). > > For example: > > ALLOWED=((600.0, 'Area 1'), (1200.0, 'Area 2') > class something(models.Model): > ... > area_charge = models.FloatField(max_digits=7, decimal_places=2, > choices=ALLOWED > ... > > The select box populates with Area 1 and Area 2, and the float gets > populated in the database correctly as 600 or 1200 based on the selection. > But after saving, say, 600.0 as the area_charge, editing that item again > yields the same select box as initial entry, but the Area 1 entry is no > longer selected; the row of hyphens is showing. Saving in this condition > elicits an error message because the entry is required. > > I'd like to see the 600.0 stored in the database cause Area 1 to be selected > when the item is opened for editing. This seems exactly like what > get_area_charge_display() should do, but I can't figure out where it goes in > the model/admin classes. > > Thanks for any light you can shed on this. > > Cheers! > -- > David Hancock | [EMAIL PROTECTED] --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---