0

I want to use this query-set to automatically delete registered users who did not activate their account : User.objects.filter(is_active=False).filter(profile__key_expires__lt=timezone.now()).delete(), but i don't know where to put it.

Views and functions need to be called to execute, but i need this code to run continuously or at least in frequent intervals.

Dan Beaulieu
  • 19,406
  • 19
  • 101
  • 135
Khalil An
  • 137
  • 13
  • What about a periodic task using [Celery](http://celery.readthedocs.org/en/latest/userguide/periodic-tasks.html)? – Aylen May 04 '15 at 18:30
  • consider using `celery` for periodic task – Yeo May 04 '15 at 18:48
  • @Filly I'm contemplating using celery as you suggested, do you think it's easier to learn vs cron ? Please post your previous comment as an answer so i can accept it. – Khalil An May 04 '15 at 19:04
  • Great, I love Celery! I added the comment as an answer and linked to another thread describing the difference between Celery and cron. – Aylen May 04 '15 at 19:24

2 Answers2

1

You can create a separate script and run it in background with cron

This is the best way not to overload your Django app. E.g here my script that loads best members and popular tags. Check how I've imported Django in it

Vladimir
  • 338
  • 7
  • 18
  • Periodic task is a new ground for me, therefore i need a well documented tool. I'm contemplating using celery as suggested by Filly, which one do you think is easier to learn? – Khalil An May 04 '15 at 19:02
  • It depends on what you know about Unix systems. Try both :) – Vladimir May 04 '15 at 19:06
  • Not much unfortunately, so i guess I'm left with celery as the only choice. +1 for pointing me to cron (i heard about it before, but never knew or had the time to search what is it for). – Khalil An May 04 '15 at 19:12
1

You can put your code in a periodic task using Celery.

Take a look at this and this threads about differences between crontab scripts and Celery.

Community
  • 1
  • 1
Aylen
  • 3,524
  • 26
  • 36