I'm using Class based generic views, can anybody suggest me how can i set the initial values to update form?
I tried using get_initial() method but didn't got any success. Following is the code which i tried
class IncidentUpdateView(UpdateView):
form_class = IncidentForm
form_class.initial = {"badge_number": '88888'}
model = Incident
template_name = 'hse/incident/incident_update.html'
def get_initial(self, form_class):
initials = {
"badge_number": '88888'
}
form = form_class(initial=initials)
return form
def get_success_url(self):
return reverse_lazy('hse-incident', args=[self.object.id])
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…