Confused about self.instance in save () of a child of ModelForm ()

The save () documentation explains that:

A subclass of ModelForm can accept an existing instance of the model as a keyword argument; if it is set, save () will update this example. If it is not specified, save () will create a new instance of the specified model

However, self.instancein save()always has an object.

So, how do you know if there is instanceor is the newly created?

+3
source share
1 answer

self.instance.pk, , . , , .

, BaseModelForm Django 1.2, self.instance._adding, True, False . , YMMV.

, , ModelForms - , , .

+6

Source: https://habr.com/ru/post/1796170/


All Articles