作者:不是我的这 | 来源:互联网 | 2023-10-11 18:51
Inthefollowingsamplecode:在以下示例代码中:fromdjango.dbimportmodelsfromdjango.db.models.signals
In the following sample code:
在以下示例代码中:
from django.db import models
from django.db.models.signals import pre_save
# Create your models here.
class Parent(models.Model):
name = models.CharField(max_length=64)
def save(self, **kwargs):
print "Parent save..."
super(Parent, self).save(**kwargs)
def pre_save_parent(**kwargs):
print "pre_save_parent"
pre_save.connect(pre_save_parent, Parent)
class Child(Parent):
color = models.CharField(max_length=64)
def save(self, **kwargs):
print "Child save..."
super(Child, self).save(**kwargs)
def pre_save_child(**kwargs):
print "pre_save_child"
pre_save.connect(pre_save_child, Child)
pre_save_parent
doesn't fire when I a Child is created:
创建Child时,pre_save_parent不会触发:
child = models.Child.objects.create(color="red")
Is this expected behaviour?
这是预期的行为吗?
2 个解决方案