I am making a custom form object in Django which has an overrided __init__ method. The purpose of overriding the method is to dynamically generate drop-down boxes based on t
You can dynamically modify your form by using the self.fields
dict. Something like this may work for you:
class TicketForm(forms.Form):
Type = Type.GetTicketTypeField()
def __init__(self, ticket, *args, **kwargs):
super(TicketForm, self).__init__(*args, **kwargs)
self.fields['state'] = State.GetTicketStateField(ticket.Type)
I found a solution here. If there is a better solution, please post a reply.
class TicketForm(forms.Form):
Type = Type.GetTicketTypeField()
def __init__(self, ticket=None, *args, **kwargs):
super(TicketForm, self ).__init__(*args, **kwargs)
if ticket:
self.fields['State'] = State.GetTicketStateField(ticket.Type)