Django - Overriding the Model.create() method?

后端 未结 7 931
忘了有多久
忘了有多久 2020-12-04 08:36

The Django docs only list examples for overriding save() and delete(). However, I\'d like to define some extra processing for my models onl

相关标签:
7条回答
  • 2020-12-04 09:42

    The preferred answer is correct but the test to tell whether the object is being created doesn't work if your model derives from UUIDModel. The pk field will already have a value.

    In this case, you can do this:

    already_created = MyModel.objects.filter(pk=self.pk).exists()

    0 讨论(0)
提交回复
热议问题