Reputation: 41
I'm building a rental application in Django which has a boolean field rental_status.
rental_status = models.BooleanField(default = False)
So, My question is how can we change rental_status to true after x time so that it can be rented again.
(I understand if my way of implementation is not good or ideal but it is just for a project. Please suggest if there are any other better implementations)
Upvotes: 0
Views: 119
Reputation: 9359
You have to store the date until which it is rented somewhere too, eg.
rented_until = models.DateField("Rented until date", null=True)
If there are no other conditions for the rental_status
, then you dont need that field anymore and you can use only this one.
To find out unrented properties, use filter()
with a value of date you are interested in (eventually take into consideration potential null
value too):
# find properties which are available from today further on
MyModel.objects.filter(rented_until__lt=date.today())
Upvotes: 1