Set initial value to modelform in class based generic views

后端 未结 1 1610
无人共我
无人共我 2020-12-08 10:47

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

相关标签:
1条回答
  • 2020-12-08 11:17

    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' }
    
    0 讨论(0)
提交回复
热议问题