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
1
vote
2 answers

Django model aggregation

I have a simple hierarchic model whit a Person and RunningScore as child. this model store data about running score of many user, simplified something like: class Person(models.Model): firstName = models.CharField(max_length=200) lastName =…
Fabrizio
  • 53
  • 1
  • 8
1
vote
2 answers

Django aggregation. How to render its value into the template?

I have came across on one of the weirdest problem which I literally can't understand. Well I was following This, but nothing helped. As the question says, I just want to render the result into the template. Below is my code. Views.py ... …
1
vote
1 answer

Django annotation resulting in cartesian product

I have a model where a particular class will have multiple child classes. Sample design: class ParentModel(models.Model): ParentName = CharField(max_length=50) class ChildModelA(models.Model): FK1 = ForeignKey(ParentModel,…
1
vote
1 answer

How to create a grouped QuerySet for use in ModelAdmin.get_queryset

I want to be able to display a list of banned ip addresses grouped by ip, sorted descending by count and the latest time of ban, as an admin changelist. fail2ban generates a sqlite-db and debian-8/fail2ban-debian-0.9.6 generates this table: "CREATE…
bitroost
  • 31
  • 1
  • 2
1
vote
1 answer

How to use annotate in query set to extract a count of type in a location?

I can't seem to properly use annotate to extract the information I need from my models. I have the follow .model structure: class ArtistWorkPlaceQuerySet(models.QuerySet): def with_related(self): return…
H C
  • 1,138
  • 4
  • 21
  • 39
1
vote
0 answers

Django orm to select field that has first three word distinct

I want top perform django orm that selects first 3 word of letter as diustinct selection I have model as below: class Phone(models.Model): country = models.ForeignKey(Country, on_delete=models.CASCADE) name =…
1
vote
1 answer

Count a Count with Django Aggregation through multiple Many to Many fields

Given a Django model with two M2M fields: class Book(models.Model): name = models.CharField(max_length=300) authors = models.ManyToManyField(Author) publishers = models.ManyToManyField(Publisher) And starting from a queryset of…
43Tesseracts
  • 4,617
  • 8
  • 48
  • 94
1
vote
1 answer

Django Serializers - Return the sum of values by filter

Following this post: Serializer - Django REST Framework - The serializer field might be named incorrectly and not match any attribute or key on the `str` instance I use this function: def get_month_hours(self): last_year = timezone.now() -…
Yann Btd
  • 409
  • 2
  • 6
  • 18
1
vote
0 answers

Django Query : Compiling data with `seconds` difference in TimeField

I have the following model in my Django application : class PeopleCount(models.Model): """ A webapp model classs to store People Count Details. """ timestamp = models.DateTimeField(auto_now=True) people_count_entry =…
Aniket Maithani
  • 845
  • 1
  • 10
  • 24
1
vote
2 answers

Django queryset with LOTS of annotations performance

Is there a limit for the number of annotations on a queryset? Will there be a significant performance hit if I add lots of (over 50) annotations to a queryset?
user4426017
  • 1,930
  • 17
  • 31
1
vote
0 answers

Multilevel annotation/aggregation using django ORM

I have been trying to implement pretty much the same thing as in query-for-total-score Does Django support multilevel aggregation? I can get the max score for each user each challenge, but I don't know how to drill down my results to fit in. s =…
Bhavani Ravi
  • 2,130
  • 3
  • 18
  • 41
1
vote
1 answer

django annotate weird behavavior (group by model.id)

In my DRF API, I have a view like this class ActivityAPI(viewsets.ModelViewSet): authentication_classes = (SessionAuthentication, TokenAuthentication) serializer_class = ActivitySerializer queryset =…
JPG
  • 82,442
  • 19
  • 127
  • 206
1
vote
2 answers

Django Aggregate Query Values for Multiple Objects

In my project I have a model called Organization that can have multiple Campaign's. Each campaign can then have multiple donor's. Hopefully to clarify here is what my models look like: class Campaign(models.Model): name = models.CharField() …
1
vote
1 answer

Django query to Sum the lengths of ArrayFields

I have this model: class Interaction(models.Model): user = models.ForeignKey(User) codes = ArrayField(models.CharField(choices=CODE_CHOICES)) and I'm trying to figure out how to do the equivalent of this SQL query in Django: select user_id,…
TAH
  • 1,658
  • 1
  • 19
  • 37
1
vote
1 answer

Nested subqueries in Django

Getting into deep water with Subquery. I have a set of Carparks. Carparks have multiple Bookings. Bookings have many BarrierActivity records, which are the various coming and going events at the barriers. These are all simple FKs up the stack. It is…
Oli
  • 235,628
  • 64
  • 220
  • 299