Django - change select items display

14 views
Skip to first unread message

galgal

unread,
Jul 19, 2011, 6:16:06 PM7/19/11
to django...@googlegroups.com

I use ModelForm. One of fields is:

repertoire = models.ForeignKey(Repertoire)

I need to change it's display type. Instead of using unicode in display I want to show name and date of repertoire. How in ModelForm I can do that?

Jani Tiainen

unread,
Aug 27, 2012, 7:54:34 AM8/27/12
to django...@googlegroups.com
27.8.2012 12:11, jm kirjoitti:
> hi
>
> do you solved it ? I'm looking for the same and do not find anything to
> change which column is used in the SELECT instead of __unicode__
>
> thanks
>
> jm
>
> Le mercredi 20 juillet 2011 00:16:06 UTC+2, galgal a �crit :
>
> I use ModelForm. One of fields is:
>
> |repertoire= models.ForeignKey(Repertoire)
> |
>
> I need to change it's display type. Instead of using *unicode* in
> display I want to show name and date of repertoire. How in ModelForm
> I can do that?
>
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/gbAncWxkSL4J.
> To post to this group, send email to django...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.

You can change it by creating custom field and overriding
label_from_instance method.

It's documented just below
https://docs.djangoproject.com/en/1.3//ref/forms/fields/#django.forms.ModelChoiceField.empty_label

HTH,

--
Jani Tiainen

- Well planned is half done and a half done has been sufficient before...
Reply all
Reply to author
Forward
0 new messages