Skip to content

Instantly share code, notes, and snippets.

@CapnKernel
Created July 7, 2016 12:24
Show Gist options
  • Save CapnKernel/328677a6ae59a3506cb7a622a26ff9dc to your computer and use it in GitHub Desktop.
Save CapnKernel/328677a6ae59a3506cb7a622a26ff9dc to your computer and use it in GitHub Desktop.
# Is also used to change details of an order, if needed.
class NewOrChangeOrderForm(forms.Form):
customer = forms.ModelChoiceField(queryset=Customer.objects.order_by('id'), empty_label='<choose>')
# ...
def __init__(self, *args, **kwargs):
super(NewOrChangeOrderForm, self).__init__(*args, **kwargs)
# Customise how we show customer name
self.fields['customer'].label_from_instance = lambda obj: "%s (%s %s)" % (obj.name, obj.firstname, obj.lastname) if obj.nick else "%s %s" % (obj.firstname, obj.lastname)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment