user1431282
user1431282

Reputation: 6845

Self-Deleting Model Object Django

How would you have a model object delete itself 60 seconds after it has been initialized? I know you could override the delete() method to have it sleep for 60 seconds before actually deleting the object. However, if I made a method call to delete() in a view. Wouldn't it just end up stalling the view for 60 seconds before continuing?

So how would I be able to do this without worrying about these stalls?

Upvotes: 0

Views: 1013

Answers (2)

Daniel Roseman
Daniel Roseman

Reputation: 600026

Put a 'to_be_deleted' booleanfield in the model, and set up a cron job to run every 60 seconds to delete all instances with the flag set.

Upvotes: 3

Rohan
Rohan

Reputation: 53386

May be you can start new thread, wait for 60 secs and delete the object. So view won't be blocked.

Another approach would be to use asynchronous task manager like Celery to start a new task to delete object after 60 secs.

Upvotes: 1

Related Questions