django 用户 update_fields 没有出现在信号中
django User update_fields not showing up in signal
我正在使用 django 信号在创建用户时自动创建用户配置文件,
它工作正常,
但我还想检查用户是否试图更新他的“用户名或电子邮件或......等”。
我正在尝试检查信号中的这些值,但总是
'update_fields' 值为 None !
'as you can see in the block of code below '
# create profile automatically when the user is created using (signal) ##
def create_profile(sender , **kwargs):
if kwargs['created']:
Profile.objects.create(PRF_user=kwargs['instance'])
if kwargs['update_fields']:
print ('some table are updated this is a test')
print('all kwargs')
print(kwargs)
print('end kwargs')
#done create profile automatically ##
post_save.connect(create_profile , sender=User)
enter image description here
outprint
all kwargs
{'signal': <django.db.models.signals.ModelSignal object at 0x00000000037D2780>,
'instance': <User: khder_admin@local.com>, 'created': False, 'update_fields': No
ne, 'raw': False, 'using': 'default'}
end kwargs
我如何告诉 Django 填充 'update_fields' 值并通过信号将其发送到我的函数!? .
您误解了 update_fields 的含义。它们用于限制应该更新的字段范围,也可以设置update_fields forces update query
如果您想知道更新了哪些字段,您应该手动检查旧的数据库实例字段和要设置的字段。 Django 不记得已更新的字段
我正在使用 django 信号在创建用户时自动创建用户配置文件, 它工作正常, 但我还想检查用户是否试图更新他的“用户名或电子邮件或......等”。 我正在尝试检查信号中的这些值,但总是 'update_fields' 值为 None !
'as you can see in the block of code below '
# create profile automatically when the user is created using (signal) ##
def create_profile(sender , **kwargs):
if kwargs['created']:
Profile.objects.create(PRF_user=kwargs['instance'])
if kwargs['update_fields']:
print ('some table are updated this is a test')
print('all kwargs')
print(kwargs)
print('end kwargs')
#done create profile automatically ##
post_save.connect(create_profile , sender=User)
enter image description here
outprint
all kwargs
{'signal': <django.db.models.signals.ModelSignal object at 0x00000000037D2780>,
'instance': <User: khder_admin@local.com>, 'created': False, 'update_fields': No
ne, 'raw': False, 'using': 'default'}
end kwargs
我如何告诉 Django 填充 'update_fields' 值并通过信号将其发送到我的函数!? .
您误解了 update_fields 的含义。它们用于限制应该更新的字段范围,也可以设置update_fields forces update query
如果您想知道更新了哪些字段,您应该手动检查旧的数据库实例字段和要设置的字段。 Django 不记得已更新的字段