Answer the question
In order to leave comments, you need to log in
How to get correct difference between date range from two models.DateField fields?
Hello.
I am building a book rental website. There are two model fields: start_date and end_date (the user sets the lease range). It was necessary to receive list from days when the book will be occupied.
I did it in the form of a model method (wrapped in @property):
class Book(models.Model):
........
@property
def get_date(self):
return [str(self.end - datetime.timedelta(i)) for i in range((self.end - self.start).days)]
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question