0

I'm using Django for developing an app for booking cars, then I need an automated code to check if a car is booked automatically every hour, I'm new in Django and I don't have idea how to do this

Salim Slimani
  • 113
  • 1
  • 6
  • Does this answer your question? [Set up a scheduled job?](https://stackoverflow.com/questions/573618/set-up-a-scheduled-job) – abhijeetviswa Apr 30 '20 at 13:37

2 Answers2

0

You can look into management commands and cronjobs. You basically create a management command that will perform a specific function. You can then schedule a cronjob to run every hour which will execute this management command.

Check out this answer as well.

abhijeetviswa
  • 113
  • 3
  • 12
0

I agree with abhijeetviswa's answer and also the linked answer that mentioned Celery (if you need something a bit more complex).

I'd also think very carefully about what it is you are trying to achieve and to consider if there is a different way to do it. Unless you are going to use Django signals to be able to respond to the user when it finds that the car is booked, you might not actually need this to be a Django thing at all.

For example, if you just wanted to know if the car was booked or not, you could consider refreshing that information just before you need to know it, (i.e. before building some results) rather than polling for it every hour.

Obviously, this depends heavily on what you want to achieve.

dh7892
  • 26
  • 5