保存对象后,我正在尝试向用户发送电子邮件。但是在发送之前无法让用户个人资料找到是否允许。
模型.py
class UserProfile(models.Model):
user = models.OneToOneField(User)
...
notifications = models.BooleanField(default=True)
...
class Follow(models.Model):
who = models.ForeignKey(User, related_name='he_follow')
whom = models.ForeignKey(User, related_name='him_follow')
...
def send_notification(sender, created, **kwargs):
if created:
obj = kwargs['instance']
check_it = obj.whom.get_profile().notifications
if check_it == True:
#rest code for sending emails works
else:
pass
post_save.connect(send_notification)
这返回错误'LogEntry' object has no attribute 'whom'
,所以我认为这是因为 post_save 中没有发件人。但是在我将 post_save 行更改为 `
post_save.connect(send_notification, sender=Follow)
django 因错误而崩溃NameError: name 'Follow' is not defined
。