文档说:
post_save
django.db.models.signals.post_save
created
A boolean; True if a -new- record was create.
我有这个:
from django.db.models.signals import post_save
def handle_new_user(sender, instance, created, **kwargs):
print "--------> save() "+str(created)
post_save.connect(handle_new_user, sender=User)
当我在 shell 中做时:
u = User(username="cat")
u.save()
>>> --------> save() True
u.username = "dog"
u.save()
>>> --------> save() True
我希望>>> --------> save() False
第二次 save() 因为是更新?不是?