[Answer]-How to let a view has an expiration age in django?

1👍

You might want to implement a 2-tier system.

The first tier is the count of sold books. As soon as you have sold 10 books. The action is finished and you can deactivate the view.

To prevent more users calling the url for the offer i’d recommend you some kind if AJAX Heartbeat:

  • User requests url
  • session is set for this user and comes with a timeout, in case this user doesn’t to anything for X Minutes/hours/etc. If timeout is reached: session will be deleted
  • offer counter is incremented by 1
  • javascript sends a keep alive heartbeat via ajax, so your system knows that user is still using that url and hasn’t moved anywhere else.
  • if the heartbeat stops: delete session and decrement offer counter by 1.

this ensures that only 10 people can look at your view at a time, but you will be able to sell all 10 books.

You might want a redirect to a different page when your counter is full?

0👍

You can add some cookies to each user and save in database cookies values with page views information. And you can save user IP address to improve your system.

Leave a comment