django-aggregation Questions

3

Solved

Consider the following: status = queryset.values('status').annotate(count=Count('status')) where status field is a CharField with choices. This will result in a list of dictionaries with status ...
Sphinx asked 31/7, 2014 at 13:49

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 ...

5

Solved

I have a model with some fields like below class Choclate(models.Model): name = models.CharField(max_length=256) price = models.IntegerField() So i want to get the field name that has the lowe...
Beating asked 30/10, 2013 at 9:10

3

Solved

I know the short answer because I tried it. Is there any way to accomplish this though (even if only on account of a hack)? class Ticket(models.Model): account = modelfields.AccountField() uuid ...
Airfoil asked 18/6, 2010 at 0:27

6

Solved

Consider simple Django models Event and Participant: class Event(models.Model): title = models.CharField(max_length=100) class Participant(models.Model): event = models.ForeignKey(Event, db_inde...
Defloration asked 10/6, 2015 at 9:22

2

I have models sth like this # models.py class MyModel( models.Model ): orders = models.JsonField(null= True, blank=True, default=list) category = models.ForeignKey(Category, on_delete=models.CASC...

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...

8

Solved

I've got a simple Model like this: class Order(models.Model): created = model.DateTimeField(auto_now_add=True) total = models.IntegerField() # monetary value And I want to output a month-by-mo...
Ferrer asked 5/1, 2012 at 16:30

4

Solved

How can I make an order_by like this .... p = Product.objects.filter(vendornumber='403516006')\ .order_by('-created').distinct('vendor__name') The problem is that I have multiple vendors with t...
Acquiescence asked 14/12, 2013 at 11:56

5

Solved

I would like to do a SUM on rows in a database and group by date. I am trying to run this SQL query using Django aggregates and annotations: select strftime('%m/%d/%Y', time_stamp) as the_date, s...
Precondemn asked 6/4, 2009 at 17:4

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 question about how we can filter by SUM of multiple columns. Example: class Foo(models.Model): i1 = models.IntegerField() i2 = models.IntegerField() i3 = models.IntegerField() And I...
Dempster asked 10/4, 2017 at 12:53

2

Solved

Doing my first real Django project, and need guidance. Background: My project is a reddit clone. Users submit links+text. Visitors upvote or downvote. There's a social_ranking algo, runs every ~2...
Overzealous asked 31/8, 2015 at 10:49

2

Solved

I'm surprised that this question apparently doesn't yet exist. If it does, please help me find it. I want to use annotate (Count) and order_by, but I don't want to count every instance of a relate...
Tarra asked 9/8, 2011 at 18:37

3

Solved

I need to get aggregated value of two columns. So first multiple them together and then get theirs sum(). Code below naturally does not work, it is just for clarification. Is it somehow possible o...
Rostand asked 9/12, 2009 at 16:41

1

Solved

I have a following model: class VotingRound(models.Model): pass # here are some unimportant fields class Vote(models.Model): voting_round = models.ForeignKey(VotingRound) vote = models.CharFi...
Norris asked 24/4, 2015 at 0:58

4

Solved

I have built a simple Django photo app. Users can upload photos, follow other users and like photos. To handle relationships amongst the users (following & unfollowing) I use a package called d...
Legman asked 3/12, 2013 at 21:18

2

Solved

I have a fairly simple query I'd like to make via the ORM, but can't figure that out.. I have three models: Location (a place), Attribute (an attribute a place might have), and Rating (a M2M 'thr...
Kinesics asked 15/11, 2012 at 18:12

1

Solved

I'm working with an Article like model that has a DateTimeField(auto_now_add=True) to capture the publication date (pub_date). This looks something like the following: class Article(models.Model):...
Pringle asked 9/3, 2012 at 16:58

1

Schema Description A project could have multiple project items, and a project item could have multiple acquisition costs. For example, capital project #1 contains two project items: Qty. 1 produc...
Warner asked 19/10, 2011 at 19:53

1

Solved

I am working on a Django app for which I have encountered a tricky aggregate query that I would like to evaluate. In the demo app of my project, I declared the following model classes for represen...
Toxicity asked 18/8, 2011 at 21:53

2

Here is my simplified model: class Item(models.Model): pass class TrackingPoint(models.Model): item = models.ForeignKey(Item) created = models.DateField() data = models.IntegerField() class...
Ebneter asked 15/5, 2010 at 6:23

2

Solved

I'm trying to get the count of the number of times a player played each week like this: player.game_objects.extra( select={'week': 'WEEK(`games_game`.`date`)'} ).aggregate(count=Count('week')) ...
Colorado asked 31/12, 2010 at 1:40

© 2022 - 2025 — McMap. All rights reserved.