Issue
I wrote a fullstack django ticketing system for a company. Everything works, login, register, posting a ticket, database, send mail to admin. Only thing that is left is to check the status field of the ticket and if its true send an email to the user who posted it.
class tickets(models.Model):
name = models.ForeignKey(devices, on_delete=models.CASCADE, blank=True, null=True)
location = models.CharField(max_length=200)
company = models.CharField(max_length=200)
serial_number = models.CharField(max_length=200)
problem = models.CharField(max_length=1000)
contact_number = models.CharField(max_length=200)
status = models.BooleanField(default=False)
author = models.ForeignKey(User, on_delete=models.CASCADE, r elated_name="authorname", null=True)
executive = models.ForeignKey(executives, on_delete=models.CASCADE, blank=True, null=True)
def __str__(self):
return self.problem
Solution
you can do like this
from django.core.mail import send_mail
class tickets(models.Model):
email_as_send = models.BooleanField(default=False)
...
def save(self):
if self.status and self.email_as_send:
send_mail("subject", "message","[email protected]", [self.author.email])
self.email_as_send = True
super().save()
Answered By - rgermain
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.