Reputation: 173
I have a function which data like this :
my_workouts = Workouts.objects.groupby('my_date').filter(
my_date__year=year, my_date__month=month)
I want to do the same with another model where I want to group the weight by date:
Models.py
class Quiz(models.Model):
owner = models.ForeignKey(User, on_delete=models.CASCADE, related_name='quizzes')
scheduled_date = models.DateTimeField(max_length=255, default=0)
weight = models.IntegerField(default=0)
What I tried:
data = Quiz.objects.orderby('scheduled_date').
filter(owner_id=request.user.pk,my_date__year=year, my_date__month=month).
annotate(c=Sum('weight')).values('c')
But this is not working, Please Help!
Upvotes: 1
Views: 107