Created
July 7, 2016 12:24
-
-
Save CapnKernel/328677a6ae59a3506cb7a622a26ff9dc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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