【发布时间】:2016-04-11 20:49:09
【问题描述】:
我正在用户模型中注册数据,并且还希望将配置文件数据同时保存在配置文件模型中,例如 first_name 和 last_name。
所以我使用 django 信号来存储配置文件信息并将邮件发送给用户。
但我们无法获取信号文件中的名字和姓氏:
#---------------------------- Create profile at the time of registration --------------------------#
def register_profile(sender, **kwargs):
if kwargs.get('created'):
user = kwargs.get('instance')
request = kwargs.get("request")
if user.id is not None and user._disable_signals is not True:
profile = Profile(user=user)
if user.status is not 1:
#------------------- Send the registration mail to user and it have confirmation link ----------#
salt = hashlib.sha1(str(random.random())).hexdigest()[:5]
activation_key = hashlib.sha1(salt+user.email).hexdigest()
key_expires = datetime.datetime.today() + datetime.timedelta(2)
#print user
profile.activation_key = activation_key
profile.key_expires = key_expires
#--------------------- End -------------------------------------------------------------#
profile.save()
if user.status is not 1:
user = model_to_dict(user)
BaseSendMail.delay(user,type='account_confirmation',key = activation_key)
return
post_save.connect(register_profile, sender=User, dispatch_uid='register_profile')
#-------------------------- End ---------------------------------------------------------------------#
在上面的代码中,我无法获取注册时发送的名字和姓氏数据。另外我想提一下,名字和姓氏字段属于配置文件模型。
【问题讨论】:
标签: python django django-rest-framework