from django.utils import timezone from review.models import Review from django.db.models import Count def weekly_report(location_id): date = timezone.now() - timezone.timedelta(days=7) reviews = Review.objects.filter(location_id=location_id, create_time__gte=date) res = Review.objects.filter(create_time__gte=date, location_id=location_id).values('star_rating')\ .annotate(total=Count('star_rating')).order_by('star_rating') # TODO: # make a table with reviews count and bad reviews and send mail to a particular email add.