Skip to content

Instantly share code, notes, and snippets.

View akshar-raaj's full-sized avatar
💭
Learning something new everyday!

Akshar Raaj akshar-raaj

💭
Learning something new everyday!
View GitHub Profile

This post is targetted towards Celery beginners. It discusses different ways to run Celery.

  • Using celery with a single module
  • Using celery with multiple modules.
  • Using celery with multiple modules split across packages.

Prerequisites

You should have Celery and Redis installed. We will use Redis as our broker.

Question.objects.values('question_text').annotate(cnt=Count('question_text'))
Question.objects.annotate(avg_votes=Avg('choice__votes'))
Choice.objects.aggregate(avg=Avg('votes'))
@akshar-raaj
akshar-raaj / total_votes_cast.py
Created August 12, 2019 09:02
Total votes cast
Choice.objects.aggregate(num_votes=Sum('votes'))
@akshar-raaj
akshar-raaj / question_with_no_choices.py
Created August 12, 2019 09:01
Question with no choices
Question.objects.annotate(num_votes=Sum('choice__votes')).filter(num_votes__isnull=True)
Question.objects.annotate(num_votes=Sum('choice__votes')).filter(num_votes__isnull=False).order_by('num_votes')[0]
Question.objects.annotate(num_votes=Sum('choice__votes')).filter(num_votes__isnull=False).order_by('-num_votes')[0]
Question.objects.annotate(num_votes=Sum('choice__votes'))
Question.objects.filter(question_text='Is the color of sky blue').annotate(choice_count=Count('choice'))