Search code examples
djangodjango-modelssendmail

Using Django to send Email to a User at a scheduled time


Currently trying to schedule a mail in django 15 Minutes to the start_time of the meeting, a email notification should be sent to the visitor, i really don't know how to go about this.

Are there schedulers i can use and how do i specify 15 Minutes before a time.

See my model structure below:

#Model for Visitor Table
class Visitor(models.Model):
    visitor_id = models.AutoField(primary_key=True)
    first_name = models.CharField(max_length=50 , blank=False, null=True)
    last_name = models.CharField(max_length=50 , blank=False, null=True)
    email = models.EmailField(max_length=50, blank=False)
    company = models.CharField(max_length=50, blank=False)
    phone_number = models.CharField(max_length=100, blank=False)
    picture_url = models.ImageField(upload_to='pictures/%Y/%m/%d/', max_length=254, blank=True, default='none', null=True)
    blacklist = models.BooleanField(default=False)

    def __str__(self):
        return '{} {}'.format(self.first_name, self.last_name)

#Model for VisitorMeeting table... This holds referencial key to both visitor table and meeting table
#Transactional table for Visitor and Meeting Table
class VisitorMeeting(models.Model):
    visitor_id = models.ForeignKey(Visitor, on_delete=models.CASCADE)
    meeting_id = models.ForeignKey(Meeting, on_delete=models.CASCADE, related_name='visitors')
    arrival = models.DateTimeField(blank=True, null=True)
    departure = models.DateTimeField(blank=True, null=True)
    checkin_status = models.BooleanField(default=False, null=True)

    objects = VisitorQuerySet.as_manager()

Solution

  • I was able to solve this problem using Django_celery and celery-beat... I calculated and saved the 15 minutes before start and 15 minutes before end of meeting and saved it on the DB at meeting creation time... I then used the values for scheduling my tasks.