I’m building a django app that has users come to my site, enter in a string of text, their email, a friend’s email and a date they would like to be emailed on.
How would I go about having the text they entered emailed to the them on the date they requested in the date_returned field? Any specific apps? Loops? Etc
Thank you,
My Models.py looks like:
class bet(models.Model):
name = models.CharField(max_length=100)
email_1 = models.EmailField()
email_2 = models.EmailField()
wager = models.CharField(max_length=300)
date_submitted = models.DateField(_("Date"), auto_now_add=True)
date_returned = models.DateField(null=True)
def __unicode__(self):
return self.name
class BetForm(ModelForm):
name = forms.CharField(widget=forms.TextInput(attrs={'placeholder': 'Bet Name'}), max_length=100)
email_1 = forms.EmailField(widget=forms.TextInput(attrs={'placeholder': 'Your Email'}))
email_2 = forms.EmailField(widget=forms.TextInput(attrs={'placeholder': 'Your Friend\'s Email'}))
wager = forms.CharField(widget=forms.TextInput(attrs={'placeholder': 'What\'s The Wager?'}), max_length=200)
date_returned = forms.DateField(widget=SelectDateWidget())
class Meta:
model=bet
In django and python it is easy to send an email so I won’t get into that. Your problem of sending an email at some particular event is not the job of a web application. I would recommend setting up a cron job that calls a django command (https://docs.djangoproject.com/en/dev/howto/custom-management-commands/). Write a simple command to dequeue events that are about to occur and send out the appropriate email. Have the cron run at a regular enough interval to simulate real time.
models.py
dequeueemail.py
crontab
* * * * * python manage.py dequeueemail
If you want to hack this without actually installing a cron check this app out (http://code.google.com/p/django-cron/)