You are not logged in.

Change Language:

Freelancer? Consultant? Check out: WorkTrail - Time Tracking made easy
Board » Django » Views » Timer in Django

Hi,

I'm using Django to create registration/payment application for a limited number of products. I want to create a timer so that when a user chooses to purchase a product, that product will then displayed as "already taken". But, if the user the user does not go through with the purchase and the timer runs out, the product goes back to status "available". If the user completes the purchase, the timer should cancel, leaving the product's status permanently as "already taken".

I've tried using python's dictionary to instantiate python Timer objects of the fly, but about 30% of the time, I get a "key error" when it's time to cancel the Timer.

Please. Could someone give me an idea on the proper way to do this in Django?

Thanks very much!
Mark
hi,

i don't think this is an appropriate way to do this - imagine the server shuts down during that period.. the product order would never be canceled.. (and e.g. in an apache process or whatever it can always happen that childs are shut down because they are currently not needed, etc.)

so i guess the most straight forward approach would be to set up a cron job which runs e.g. every 5 minutes.. and checks in the database when which item was chosen by which user.. and if the timeout has been reached. and then simply marks the item as being available again.

i guess you could set up a management command and simply run it from crontab with "/path/to/my/project/manage.py expireproductpurchaces" or whatever :)

hope that helps ..
Hi,
I think you can do this with jquery countdown plug-in hre you can see some examples:
http://davidwalsh.name/jquery-countdown-plugin
Sincerly Yours.





Powered by Sphene Community Tools