On Mon, Aug 8, 2011 at 2:56 PM, Daniel Roseman <dan...@roseman.org.uk> wrote:
>
> I'm afraid it's really not clear what you're trying to do, or what the
> problem is.
> If the issue is that you have a field referring to a foreign key, and you
> want to change what the values displayed in the dropdown for that field,
> then you simply need to redefine the `__unicode__` method for the related
> model, as documented
> here: https://docs.djangoproject.com/en/1.3/ref/forms/fields/#modelchoicefield
> An alternative, also documented at that link, is to subclass
> ModelChoiceField and override label_from_instance.

This exact question gets asked about 3 times a week (well, once you
have normalized out the different ways in which it is asked..).
Personally, I'm fed up of answering it.

I think that adjusting the labels needs to become a bit more flexible
- perhaps allow a "label_from_instance=callable" argument on
ModelChoiceField, or have ModelChoiceField look for a
MyForm.label_from_instance_<fieldname> method.

The current options are

a) change how the related field's model is displayed throughout Django
(which may be impossible to do for a cross app links/3rd party apps)
b) provide your own Field class which labels things appropriately

Both these options are more cumbersome than needs be, as evidenced by
the number of users who don't understand how to do this.

Cheers

Tom

-- 
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.

Reply via email to