Created
August 5, 2016 08:48
-
-
Save kezabelle/4795a5ba35b37d1298974a6373cb97cd to your computer and use it in GitHub Desktop.
how to change the display value for a ModelChoiceField, for mike_papa in #django IRC
This file contains hidden or 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
class MyModelChoiceField(ModelChoiceField): | |
def label_from_instance(self, obj): | |
return "hello" | |
# or | |
class MyForm(Form): | |
def __init__(self, *args, **kwargs): | |
super(MyForm, self).__init__(*args, **kwargs) | |
if 'myfield' in self.fields: | |
self.fields['myfield'].label_from_instance = lambda obj: "also hello" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment