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