Count number of records by date in Django

后端 未结 5 987
失恋的感觉
失恋的感觉 2020-11-28 23:49

I have a model similar to the following:

class Review(models.Model):
    venue = models.ForeignKey(Venue, db_index=True)
    review = models.TextField()  
           


        
5条回答
  •  迷失自我
    2020-11-29 00:27

    If you were storing a date field, you could use this:

    from django.db.models import Count
    
    Review.objects.filter(venue__pk = 2)
        .values('date').annotate(event_count = Count('id'))
    

    Because you're storing datetime, it's a little more complicated, but this should offer a good starting point. Check out the aggregation docs here.

提交回复
热议问题