Skip to content Skip to sidebar Skip to footer

Override Label In Django Forms

I have 3 sections with identical fields, except for label on 'title' field. For all of them I'm using same Django Form. In views I have: def get(self): context = self.CONTEXT_

Solution 1:

You need to override its constructor

class InvoiceContentForm(forms.Form):
     def __init__(self, title, *args, **kwargs):
          super().__init__(*args, **kwargs)
          self.fields['title'].label = title

context.section1 = InvoiceContentForm('foo')

Post a Comment for "Override Label In Django Forms"