Django: using ModelForm to edit existing database entry

后端 未结 2 976
日久生厌
日久生厌 2020-12-05 04:42

I have created a ModelForm class to be able to create and edit database entries. Creating new entries works well, however, i dont know how to use ModelForms to edit/update a

2条回答
  •  一整个雨季
    2020-12-05 05:10

    Also possible and slightly shorter:

    instance = MyModel.objects.get(whatever)
    form = MyModelForm(request.POST or None, instance=instance)
    ...
    

提交回复
热议问题