koenb
unread,Mar 20, 2008, 8:50:47 AM3/20/08Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Django users
Hi all,
has anyone used label_from_instance yet for ModelChoiceField
(introduced in r7326)?
It seems to get it to work, I have to redefine the queryset on the
field first.
What I mean is:
suppose I have a form (newforms that is)
class Aform(forms.Form):
user = forms.ModelChoiceField(queryset=User.objects.all())
def __init__(self, *args, **kwargs):
super(Aform, self).__init__(*args, **kwargs)
# without the next line label_from_instance does NOT work
self.fields['user'].queryset = User.objects.all()
self.fields['user'].label_from_instance = lambda obj: "%s %s"
% (obj.last_name, obj.first_name)
If I do not redefine the queryset, it does not work. If I do, it does.
Is this a bug or was this not the intended use for
label_from_instance ?
Koen