Re: Order SelectField items
I solved this by sorting the tuple of tuples outside of the add/create custom manipulators, then using that sorted list instead of ColorAccount.COLORS: col_list = list(ColorAccount.COLORS) col_list.sort(lambda x, y: cmp(x[1], y[1])) col_tuple = tuple(col_list) And then: forms.SelectField(field_name="fav_color",choices=col_tuple) I guess this was more of a python issue. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Order SelectField items
Hello, This is a simplified example of what I'm trying to accomplish. In my model I have the following objects and fields: class ColorAccount(models.Model): COLORS = ( (0, 'Red'), (1, 'Orange'), (2, 'Yellow'), (3, 'Green'), ... ) fav_color = models.IntegerField(choices=COLORS) ... I then have a custom manipulator, which has the following field: forms.SelectField(field_name="fav_color", choices=ColorAccount.COLORS), My question is, is it possible to change the default order (corresponding integer values) of the items in the generated HTML menu ... without reassigning the integer values in the model? For instance, I would like the order to be alphabetical. Would this be something I could accomplish via the manipulator, or maybe back in the model? Thanks in advance, Andy --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Order SelectField items
Hello, This is a simplified example of what I'm trying to accomplish. In my model I have the following objects and fields: class ColorAccount(models.Model): WINE_VARIETALS = ( (0, 'Red'), (1, 'Orange'), (2, 'Yellow'), (3, 'Green'), ... ) fav_color = models.IntegerField(choices=COLORS) ... I then have a custom manipulator, which has the following field: forms.SelectField(field_name="fav_color", choices=ColorAccount.COLORS), My question is, is it possible to change the default order (corresponding integer values) of the items in the generated HTML menu ... without reassigning the integer values in the model? For instance, I would like the order to be alphabetical. Would this be something I could accomplish via the manipulator, or maybe back in the model? Thanks in advance, Andy --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---