Labels for Django select form field Labels for Django select form field django django

Labels for Django select form field


Check out the Django docs regarding the ModelChoiceField. Quote:

The __unicode__ method of the model will be called to generate string representations of the objects for use in the field's choices; to provide customized representations, subclass ModelChoiceField and override label_from_instance. This method will receive a model object, and should return a string suitable for representing it. For example:

class MyModelChoiceField(ModelChoiceField):    def label_from_instance(self, obj):        return "My Object #%i" % obj.id