Pre-populate HTML form table from database using Django

前端 未结 3 1390
太阳男子
太阳男子 2021-02-11 02:24

I have a class-based view (IndexView at views.py) that shows a table with all the data stored in the database. This view is rendered in index.html<

3条回答
  •  情话喂你
    2021-02-11 03:18

    There are multiple ways of loading data into forms, as far as I know:

    • In views.py

    You are using FormView CBV which has a func called get_intial:

        def get_initial(self):
            initial = super().get_initial()
            initial[''] = 
            return initial
    
    • In forms.py

    You can override the init func:

        def __init__(self, *args, **kwargs):
            super().__init__(*args, **kwargs)
            self.fields[''].initial = 
    

提交回复
热议问题