1

The Goal: Once a user has signed up they start a challenge. Once they've started the challenge I'd like to be able to send users weekly emails for 12 weeks (Or however long the challenge lasts for). Bearing in mind, one user may sign up today and one may sign up in three months time. Each week, the email will be different and be specific to that week. So I don't want the week one email being sent alongside week 2 for 12 weeks.

Should I add 12 boolean fields inside the extended User model, then run checks against them and set the value to True once that week gas passed?

Assuming this is the case. Would i then need to setup a cron task which runs every week, and compares the users sign up date to todays date and then checks off the week one boolean? Then use the post_save signal to run a check to see which week has been completed and send the 'week one' email?

I hope that makes sense and i'm trying to get my head around the logic. I'm comfortable with sending email now. It's trying to put together an automated process as currently it's all manual.

Please let me know if I need to elaborate on anything. Any help would be much appreciated.

JDavies
  • 2,730
  • 7
  • 34
  • 54

2 Answers2

2

The easiest way would be something like this:

  • Make a table e.g. challenge in database with following cols: challenge_name, week1, week2, ..., as much weeks as you need. Make them nullable, so if some challenge is shorter, the rest of weeks can be null.
  • In users table (or you can make new one) add two cols, one for active challenge, the other for day started.
  • Then yes, you can run cron job daily, or maybe twice a day, in the morning and in the afternoon, that executes python function for sending mail. In that function you go through all users, check their current challenge, calculate the week they are in, query table challenge for mail content and then send.

I think this is the best solution, certainly the most simple and solid one :)

campovski
  • 2,979
  • 19
  • 38
  • Thank you! Didn't think of creating a new model but that would be really beneficial as i'll then be able to create a 6 week and a 12 week challenge. The only thing i'm not 100% confident with as when it comes to calculating which week they are in. But I'll see whether i can get the initial logic working and play around with it. Thanks again. – JDavies Aug 30 '17 at 08:53
  • 1
    No problemo, amigo! :) Week difference: [https://stackoverflow.com/questions/14191832/how-to-calculate-difference-between-two-dates-in-weeks-in-python](https://stackoverflow.com/questions/14191832/how-to-calculate-difference-between-two-dates-in-weeks-in-python) – campovski Aug 30 '17 at 09:05
  • 1
    Thank you. I've now marked as answered. Took me a day to get the logic right, but i've managed to set it up. I'm yet to link my logic with the cron task, but that should be the easy part. Thanks again, really appreciate it. – JDavies Sep 05 '17 at 07:55
  • Glad you solved it and glad I was able to help you! :) Cron job should be the easy part, google knows the answer. – campovski Sep 05 '17 at 07:56
0

You definitely need to use cron task - I recommend Celery. I think that you just need to build 12 templates (for every week, or maybe building less and use different parameters in the message) in your mailing service and name them with a format (for example {challenge_name}-{week_num}). Every week when your cron task runs target the email message that you want to send by calculating the number weeks from the user registration date and planting it in your format to choose the correct email.

shlomta1
  • 148
  • 1
  • 11