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
1 answer

annotation in admin list with many to many relation

I have a link between ads and products and stores, and I want to sort them in the admin by store: class Ad(models.Model): products = models.ManyToManyField(Product, blank = True) device = models.ForeignKey(Display, on_delete =…
xtlc
  • 1,070
  • 1
  • 15
  • 41
0
votes
0 answers

Can I use an annotated subquery parameter later on in the same query?

I have a Django queryset that ideally does some annotation and filtering with 3 object classes. I have Conversations, Tickets, and Interactions. My desired output is Conversations that have 1. an OPEN ticket, and 2. exactly ONE interaction, of type…
ezeYaniv
  • 412
  • 5
  • 18
0
votes
2 answers

How to aggregate sum of several previous aggregated values in django ORM

In use: django 3.2.10, postgresql 13.4 I have next query set with aggregation function Count queryset = Model.objects.all().aggregate( trues=Count('id', filter=Q(criteria=True)), falses=Count('id', filter=Q(criteria=False)), ) What I…
Vadim Beglov
  • 343
  • 1
  • 4
  • 15
0
votes
0 answers

Django QuerySet calculate sum of values according to a another attribute

I need some help for the creation of 2 queryset . Calculates the total of amounts of the objects considering the user as a common attribute. Given a specific user, calculate considering the categories, ordering the result in "in" and "out". This…
0
votes
1 answer

django related field subset average

i have two models in django app UserDay model: class UserDay(models.Model): date = DateField() @property def avg(self): return self.activities.aggregate(Avg('point')) Activity model: class Activity(models.Model): point =…
0
votes
1 answer

Django Annotation Count with Subquery & OuterRef

I'm trying to create a high score statistic table/list for a quiz, where the table/list is supposed to be showing the percentage of (or total) correct guesses on a person which was to be guessed on. To elaborate further, these are the models which…
0
votes
2 answers

How to find the percentage of employee scores using django

I have a table called Task. It captures task, task score and the employee it is assigned to. I want to calculate the performance of the employee using his total task scores for the week (duration should be dynamic. preferably input field) and the…
0
votes
1 answer

Django-Using distinct on a specific field with annotate

I have following models: class Post(models.Model): title = models.CharField(max_length=30) class PostView(models.Model): post = models.ForeignKey(Post, related_name='views', on_delete=models.CASCADE) user =…
msln
  • 1,318
  • 2
  • 19
  • 38
0
votes
1 answer

Annotating with the count of a subquery filtering by jsonb fields in Django

I have a single model with a jsonb field. There is a value inside this jsonb field that can be shared amongst other rows. I am trying to get the count of a subquery while filtering by this jsonb field. Some pseudo code of what I have been attempting…
0
votes
1 answer

Username is not showing but user id is showing in html template in Django

Below is my Model : class Problem_Solved(models.Model): user_ref = models.ForeignKey(User, on_delete=models.CASCADE) contest_ref = models.ForeignKey(Contest, on_delete=models.CASCADE) problem_ref = models.ForeignKey(Problem,…
0
votes
1 answer

Get max value from a set of rows

This question is in relation to project 2 of the cs50 course which can be found here I have looked at the following documentation: Django queryset API ref Django making queries Plus, I have also taken a look at the aggregate and annotate…
name-andy
  • 423
  • 1
  • 5
  • 15
0
votes
1 answer

Django Counting related object with a certain condition

I have this model classes in my django app: class Ad(models.Model): ... class Click: time = models.DateTimeField(auto_now_add=True) ip = models.GenericIPAddressField() ad = models.ForeignKey( to=Ad, …
0
votes
1 answer

Passing an Aggregate Sum to an Html page by Class Based Views on Django

Currently using aggregation for the first time, attempting to get a sum of all 'transactions' and display them on my HTML page. I am using generic class based views, currently in my function it is displaying transactions that are created by the…
0
votes
1 answer

Count on big Django Datas

I have a LogTable with about 500k entries per week. models.py class Log(models.Model): timestamp= models.DateTimeField() name = models.CharField(max_length=30) status = models.PositiveIntegerField() objects = LogManager() I want to…
Amiribus
  • 11
  • 3
0
votes
1 answer

Django aggregate ForeignKey hierarchy

Let's say I have the models Foo, Bar and FooBar. Bar has a ForeignKey reference to Foo. FooBar has a ForeignKey reference to Bar. Given a Foo-object, how do I most efficiently gather all related FooBar objects? I don't like using this: foobars =…