Django annotate field value from external dictionary

Lets say I have a following dict: schools_dict = { ‘1’: {‘points’: 10}, ‘2’: {‘points’: 14}, ‘3’: {‘points’: 5}, } And how can I put these values into my queryset using annotate? I would like to do smth like this, but its not working schools = SchoolsExam.objects.all() queryset = schools.annotate( total_point = schools_dict[F(‘school__school_id’)][‘points’] ) Models:… Read More Django annotate field value from external dictionary

Django annotating fields with null values

I have list of Demand objects that have allocated field that would either be null or have a name (denoting this demand’s allocation). I use annotations to count allocated/unallocated numbers per team: Demand.objects.filter(project=project).values(‘team’).annotate( unallocated=Count(‘allocated’, filter=Q(allocated__isnull=True)), allocated=Count(‘allocated’, filter=Q(allocated__isnull=False)) ) What’s weird is that the numbers for the allocated annotation come out right, but the numbers for… Read More Django annotating fields with null values

Django annotate() is not adding up the number of entries but is instead repeating them

Background: The Amazon Kindle PaperWhite stores the words we lookup while reading into a sqlite3 database called vocab.db. I am working on a small kindle companion app that takes this db file and imports it into a django table for various processing. I have done this step already. What I would like to do: I… Read More Django annotate() is not adding up the number of entries but is instead repeating them