简体   繁体   English

关于post_save信号和创建的参数

[英]about the post_save signal and created argument

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_save
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? 我期望>>> --------> save() False第二次>>> --------> save() False ,因为是更新吗? not? 不?

我建议您使用User.objects.create_user避免批量操作。

似乎您已经实现了自己的用户,而用户名没有唯一的限制?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM