Questions tagged [django-aggregation]

django-aggregation refers to an ability to aggregate a collection of objects provided by Django database-abstraction API

django-aggregation refers to an ability to aggregate a collection of objects provided by Django database-abstraction API.

See documentation.

206 questions
0
votes
2 answers

Ordering query objects in django

I'm trying to order the results of my query in a sort of parent/child manner. I'm wondering if there's an easy way to accomplish this. Object: Video : [id, parent_id, date] // where parent_id can be null - meaning it is a 'root' node. Queryset…
9-bits
  • 10,395
  • 21
  • 61
  • 83
0
votes
0 answers

Django distincted queryset slicing does not have consistency

I have queryset of empoyees-attendance and i am doing aggregation & disctinction on (current day, employee code). I got distincted queryset, Afterthat i am doing slicing, and found slicing consistency not happenning as we are expecting. I am adding…
NANDHA KUMAR
  • 465
  • 4
  • 11
0
votes
0 answers

django aggregate a list of dictionaries

I have a queryset with complex relations, and I need to retrieve specific data from it using aggregations. My data structure looks like this: filters = [{ 'colors': [ {'black': '#000000'}, {'white': '#111111'} …
scaryhamid
  • 345
  • 2
  • 9
0
votes
1 answer

Django ORM: This queryset contains a reference to an outer query and may only be used in a subquery

In the queryset, I want to get the average of what subquery returns and then group by 'store_id' and 'avg_sales'. However, when I used the following queries: subquery = StoreStatistics.objects.filter( store=OuterRef("store_id"), …
0
votes
0 answers

Why does Annotate and Count in Django behave this way?

I have two models Post and Tag(given by django-taggit app). So they make use of generic foreign key concept. If i query posts like: posts = Post.objects.annotate(num_tags=Count('tags')) and try to retrieve value of num_tags for first result in…
0
votes
0 answers

Django annotate with dynamic value

Hi in my model i have property that fully is in cache, not in database class Model(models.Model): .... @property def _get_last_seen_cache_name(self) -> str: return f'{self.hostname.upper()}_last_seen' @property def…
Elendiar
  • 37
  • 5
0
votes
1 answer

Django group by foreign key aggregation

I have three models like this: class Coin(models.Model): symbol = models.Charfield() class User(models.Model): phone_number = models.Charfield() class Portfo(models.Model): class Meta: unique_together = ( …
0
votes
2 answers

Get average of multiple ratings values from different model instances (Django)

I'm working on this web-app that lets a project manager rate a vendor after finishing a task/job. Here is the models.py content: class Rating(models.Model): RATE_CHOICES = [ (1, 'Below Expectation greater than 0.02'), (2, 'Meet…
henoker
  • 99
  • 8
0
votes
0 answers

How do I count the number of rows with the same date but different type?

I have a model like this: class Class(models.TextChoices): STANDARD = "Standard", _("Standard") JWW = "JWW", _("JWW") class Competition(models.Model): cls = models.CharField(choices=Class.choices) date = models.DateField() I would…
Quontas
  • 400
  • 1
  • 3
  • 19
0
votes
0 answers

Optimizing Django Aggregation Over Subsets

I'm currently trying to do some summary statistics calculations for date-based subsets of a large "competition" table (~3M rows) stored in SQLite. Specifically, I'm trying to calculate statistics for: this year last year the lifetime of the…
Quontas
  • 400
  • 1
  • 3
  • 19
0
votes
0 answers

Django annotate and aggregate not suport Timefild for sum

How can I make the total time sum of each user being that annotate and aggregate have no support for Timefild Models: class Pireps(models.Model): ... flight_time = models.TimeField(auto_now=False, auto_now_add=False, null=True) Views: def…
0
votes
1 answer

Aggregate Sum shows total for all members

When i add aggregate function on my get_context_data it shows the total for all members and not according to there ID. Thank You ItemListView class ItemListView(ListView): model = HBTYItem template_name =…
0
votes
0 answers

Aggregate return null values if queryset is none even if using Coalesce with default value

currently, I am trying to aggregate on queryset. it's working perfectly but the problem is if my queryset is none Coalesce function is not working so default value is set null rather than 0 . aggregated_data = queryset.aggregate( …
0
votes
2 answers

Counting the children matching grandchildren conditions in a single Django query

Given the following models: class Flight: class Checklist: flight = ForeignKey(Flight) class Item: checklist = ForeignKey(Checklist) completed = BooleanField() I need to get the number of completed checklists for each flight. A…
0
votes
2 answers

Django annotate count of subquery items - ValueError: This queryset contains a reference to an outer query and may only be used in a subquery

I have an Agent, Client and Car models. In Client model: agent = ForeignKey('Agent'...) In Car model: client = ForeignKey('Client'...) I want to annotate (on an Agent QuerySet) a total number of active cars of all clients of an agent. So if the…
Milano
  • 18,048
  • 37
  • 153
  • 353