docs说:
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
?不?
答案 0 :(得分:0)
好像你已经实现了自己的User,它没有对用户名的唯一约束?
答案 1 :(得分:0)
我建议您使用User.objects.create_user
来避免批量操作。