0

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?

4

2 に答える 2

3

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.

于 2013-01-03T10:29:09.280 に答える
1

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.

于 2013-01-03T04:19:23.697 に答える