📜  创建模型时的 django 操作 - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:48.281000             🧑  作者: Mango

代码示例1
# override create model method (django)

class MyModel(models.Model):
  name = ....
  ........
  .......
  def save(self, *args, **kwargs):
      if not self.pk:
          # This code only happens if the objects is
          # not in the database yet. Otherwise it would
          # have pk
          
          # -- do your custom actions here --
          
      super(MyModel, self).save(*args, **kwargs) # activate the default method on update