[Django]-Set initial value to modelform in class based generic views

55👍

You should define a get_initial method which returns a dictionary that contains the initial values:

class IncidentUpdateView(UpdateView):

    def get_initial(self):
        return { 'value1': 'foo', 'value2': 'bar' }

Alternatively, you can define an initial value:

class IncidentUpdateView(UpdateView):
    initial = { 'value1': 'foo', 'value2': 'bar' }

Leave a comment