【发布时间】:2016-01-17 22:33:52
【问题描述】:
我想向所有具有顾问权限的用户发送电子邮件:perms.profiles.consultant_permission
我的代码如下:
model.py
class Profile(models.Model):
//some attributes
class Meta:
permissions = (
('consultant_permission', 'Consultant Permission'),
)
view.py
consultant_msg_html = render_to_string('email/consultant_review_email.html', context)
send_mail("Register sent to review",
consultant_msg_html,
registration.consultant.email,
[registration.consultant.email,],
html_message=consultant_msg_html,
fail_silently = False)
我怎样才能做到这一点?
【问题讨论】:
-
您可以覆盖 Django 默认用户模型,以创建
Profile类 (more here),您可以为该模型设置属性permissions,并过滤具有顾问权限的用户,获得他们的电子邮件列表并发送电子邮件(在您的views.py中)。 -
我假设您的配置文件模型已经链接到用户帐户。看看这里如何获取用户查询集:stackoverflow.com/a/992329/640916