I want to send an email to users from django admin panel and store the sent mail in the database too. I have two usertypes: 1.Staff 2. Students. When I select staff and give email, it'll send an email to all the staff who are all having " usertype=staff " in User model and vice versa. I found some difficulties to send the mail from the admin panel. Please some one give me an idea.
models.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)
admin.py
admin.site.register(newsletter)
Perhaps an admin action would be suitable.
See also: sending email in Django .
Well Looking at the doc I found that you can add views to your admin site
extending get_urls function
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.