On Tue, Jan 20, 2009 at 12:45 PM, Flo Ledermann <lederm...@ims.tuwien.ac.at>wrote:
> > Hi all, > > I want to change the default label for the None value in a > ModelChoiceField from the default '--------' to something more > meaningful in the context of my app. > > After some research I tried subclassing the ModelChoiceField, > overriding the label_from_instance method like so: > > class MyModelChoiceField(ModelChoiceField): > def label_from_instance(self, obj): > if obj: > return 'Something' > else: > return 'Nothing here' > > which results in all the labels of object choices correctly changed to > 'Something', but still '-------' for the None choice and not 'Nothing > here' as I would have expected. Any suggestions how I could change > that default value, preferrably even without introducing my own > subclass? > >From a brief glance at the source, try specifying empty_label='whatever you want' as a parameter to the ModelChoiceField. This probably should be documented, but I can't find it. Karen --~--~---------~--~----~------------~-------~--~----~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---