django-annotate Questions

2

I'm using Django's postgres-specific ArrayAgg aggregator. It works fine but when the list is empty I get [None] instead of []. Is there any way to filter these null values out? I've tried to pass a...

3

Solved

Please help me I've been stuck on this for way too long :( What I want to do: I have these two models: class Specialization(models.Model): name = models.CharField("name", max_length=64) class ...

2

Suppose I have a object model A, and it has a field called created, which is a datetime type field. If I use annotate to count how many A are created each day, I can use A.objects.annotate(date=...
Dulciedulcify asked 27/7, 2018 at 17:28

1

From the django docs on annotate(): Annotates each object in the QuerySet with the provided list of query expressions. An expression may be a simple value, a reference to a field on the model ...
Weal asked 28/12, 2016 at 3:17

4

Solved

I have a Booking model that has start and end datetime fields. I want to know how many days a booking covers. I can do this in Python but I need this value for further annotations. Here's what I'v...

4

Django's QuerySet has two methods, annotate and aggregate. The documentation says that: Unlike aggregate(), annotate() is not a terminal clause. The output of the annotate() clause is a QuerySet. ...
Sines asked 2/11, 2011 at 14:18

3

Solved

Consider a table called DataTable. It has two fields: A and B. I want to return all rows from this table, and annotating a field called C which is a concatenation of A and B fields. Here is what I ...

0

I've got a few models and am trying to speed up the page where I list out users. The issue is that I was leveraging model methods to display some of the data - but when I listed the Users out it wa...

3

Solved

An simplified example of my model structure would be class Corporation(models.Model): ... class Division(models.Model): corporation = models.ForeignKey(Corporation) class Department(models.Mod...
Waikiki asked 25/6, 2018 at 14:11

7

Solved

This is a bleeding-edge feature that I'm currently skewered upon and quickly bleeding out. I want to annotate a subquery-aggregate onto an existing queryset. Doing this before 1.11 either meant cus...
Ardolino asked 1/3, 2017 at 23:18

3

Let's say I have the following model structure: Parent(): Child(): parent = ForeignKey(Parent) GrandChild(): child = ForeignKey(Child) state = BooleanField() num = FloatField() I'm trying to f...

1

Solved

Using Django I have a field which is of type JSONField. I am wanting to get a distinct count on a nested key/value in the json. With a normal field you can just do soemthing like the following mo...
Swadeshi asked 8/3, 2019 at 7:26

2

I am just learning the geo-django. I can find out the distance of all places from a point. But when I use .values method to the annotated distance field, I am getting TypeError: Object of type 'D...
Maclean asked 28/7, 2017 at 15:13

1

Solved

I'm currently trying to annotate and count some dates, based on the number of times they appear. visits = Subs.objects.filter(camp=campdata, timestamp__lte=datetime.datetime.today(), timestamp__gt...
Killarney asked 7/10, 2018 at 9:31

2

Solved

I have a model called Post which has two fields upvotes and downvotes. Now, upvotes, downvotes are ManyToManyField to a Profile. This is the model: class Post(models.Model): profile = models.Fore...
Leonardoleoncavallo asked 6/8, 2018 at 5:34

1

Solved

I am trying to query and annotate some data from my models: class Feed(models.Model): # Feed of content user = models.ForeignKey(User, on_delete=models.CASCADE) class Piece(models.Model): # Piec...

2

Solved

I have a model called 'StoreItem' and a model named 'QuoteItem'. A QuoteItem points on a StoreItem. I'm trying to annotate a counter of how many quote items point on store items, but with conditio...

3

Solved

In the process of finding a solution for Django ORM order by exact, I created a custom django Func: from django.db.models import Func class Position(Func): function = 'POSITION' template = "%(f...
Banjermasin asked 26/9, 2017 at 12:51

1

Solved

I have the following two models. class Product(models.Model): product_group=models.ForeignKey('productgroup.ProductGroup', null=False,blank=False) manufacturer=models.ForeignKey(Manufacturer, nu...
Bandit asked 4/8, 2017 at 12:29

2

Solved

I'm trying to use django annotation to create queryset field which is a list of values of some related model attribute. queryset = ... qs = queryset.annotate( list_field=SomeAggregateFunction( C...
Henceforth asked 4/4, 2017 at 9:17

1

Solved

I have many objects and 3 of them have name='AAA' I group them by 'name' and annotate num in group: my_models = MyModel.objects.order_by('name').values('name').annotate(count=Count('name')) for ...
Dividend asked 11/12, 2016 at 22:4

2

Solved

I need to be able to sort on the aggregate of two annotated columns So I'd like to do something like this: c = c.annotate(metric=Sum('results__metric')) c = c.annotate(metric_prior=Sum('results__...
Maldives asked 28/6, 2013 at 22:15
1

© 2022 - 2024 — McMap. All rights reserved.