background_job.py 559 B

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