Created
July 24, 2023 03:33
-
-
Save grizmio/75b3bbed860c14b7bd4952e9788fd701 to your computer and use it in GitHub Desktop.
Django ModelChoiceField label to "title"
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
from django.template.defaultfilters import title | |
class LabelToTitle: | |
def __init__(self): | |
self.label = title(self.label) | |
class FooBarModelChoiceField(forms.ModelChoiceField, LabelToTitle): | |
def label_from_instance(self, obj): | |
return obj.name |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment