我想从 django 管理面板向用户发送电子邮件,并将发送的邮件也存储在数据库中。我有两种用户类型:1.Staff 2.Student。当我选择员工并发送电子邮件时,它会向所有在 User 模型中具有“ usertype=staff ”的员工发送一封电子邮件,反之亦然。我发现从管理面板发送邮件有些困难。请有人给我一个想法。
模型.py
username = models.CharField()
first_name = models.CharField()
last_name = models.CharField()
email = models.EmailField()
password = models.CharField()
companyname=models.CharField()
usertype=models.CharField()
is_staff = models.BooleanField()
is_active = models.BooleanField()
is_superuser = models.BooleanField()
last_login = models.DateTimeField()
date_joined = models.DateTimeField()
groups = models.ManyToManyField()
user_permissions = models.ManyToManyField()
class newsletter(models.Model):
USERTYPES = (
('staff', 'staff'),
('student', 'student'),
)
usertype=models.CharField(max_length=50,choices=USERTYPES)
subject=models.CharField(max_length=100)
message=models.TextField(blank=True)
sentdate=models.DateTimeField(auto_now = True)
管理员.py
admin.site.register(newsletter)