analytics.py 409 B

12345678910
  1. from django.db.models import Count
  2. from django.utils import timezone
  3. from .models import YelpReview
  4. def get_weekly_summary(location_id):
  5. date = timezone.now() - timezone.timedelta(days=7)
  6. reviews = YelpReview.objects.filter(location__location_id=location_id, date_posted__gte=date)
  7. rating = reviews.values('rating').annotate(total=Count('rating')).order_by('-rating')
  8. return reviews, rating