Answer the question
In order to leave comments, you need to log in
How to fetch data in date range?
I use Django Rest API, before serialization, I need to pull data from the database in the date range from "2020-01-05" to "2020-01-28".
class User(models.Model):
first_name = models.CharField(max_length=50)
last_name = models.CharField(max_length=50)
class Statistic(models.Model):
user_id = models.ForeignKey(User, on_delete=models.CASCADE, related_name='statistic')
date = models.DateField()
page_views = models.IntegerField()
User.objects.get(pk=pk).statistic.exclude(date__gte='2020-01-18').filter(date__gte='2019-01-08')
Answer the question
In order to leave comments, you need to log in
Something like:
User.objects.filter(statistic__date__range=['2019-01-08', '2020-01-18'])
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question