gpt4 book ai didi

python - 关于 post_save 信号和创建的参数

转载 作者:太空宇宙 更新时间:2023-11-04 06:39:40 27 4
gpt4 key购买 nike

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

最佳答案

似乎您已经实现了自己的用户,它对用户名没有唯一约束?

关于python - 关于 post_save 信号和创建的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2399197/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com