开发者

about the post_save signal and created argument

开发者 https://www.devze.com 2022-12-22 09:24 出处:网络
the docs says: post_save django.db.models.signals.post_save created A boolean; True if a -new- record was create.

the docs says:

post_save
django.db.models.signals.post_save

created
A boolean; True if a -new- record was create.

and I have this:

from django.db.models.signals import post_sa开发者_StackOverflow中文版ve
def handle_new_user(sender, instance, created, **kwargs):
    print "--------> save() "+str(created)
post_save.connect(handle_new_user, sender=User)

when I do in shell:

u = User(username="cat")
u.save()
>>> --------> save() True
u.username = "dog"
u.save()
>>> --------> save() True

I expect a >>> --------> save() False when I save() the second time because is an update? not?


Seems like you have implemented your own User which doesn't have a unique constraint on username?


I suggest you use User.objects.create_user to avoid bulk operation.

0

精彩评论

暂无评论...
验证码 换一张
取 消