Skip to content

Instantly share code, notes, and snippets.

@qoelet
Created October 24, 2011 12:24
Show Gist options
  • Save qoelet/1308901 to your computer and use it in GitHub Desktop.
Save qoelet/1308901 to your computer and use it in GitHub Desktop.
class MyCustomModelChoiceField(ModelChoiceField):
def label_from_instance(self, obj):
mapping = {
"A1": "B1",
"A2": "B2",
# ... etc
}
if obj.name in mapping.keys():
return "New type - %s" % (mapping[obj.name])
else:
# default back to original functionality
return smart_unicode(obj)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment