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

How to select data from a queryset and group by counts for a specific date

When I query my database I get the same entry three times with three different counts. In the result list I would like to get just one entry showing the sum of these counts. What I would like to display is the total for a specific period. In my…
Py_Bear
  • 23
  • 5
0
votes
1 answer

Django 2.1 - 'WhereNode' object has no attribute 'output_field' error

I am trying to filter some annotations in a ViewSetlike so: queryset = Confirmation.objects.values('prediction__specimen_id').annotate( sample_id=F('target_prediction__specimen_id'), num_selected=Count('selected', filter=Q(selected=True)), …
0
votes
1 answer

How to use or extend Django admin to navigate thru aggregated data?

I would like to know how could I extend Django admin in order to be able to navigate the records using aggregated data. For example: browse data aggregated by date, month, day, day of the week and see average, max/min or total for other fields.
sorin
  • 161,544
  • 178
  • 535
  • 806
0
votes
1 answer

Perform trigonometric operations or any mathematical expression in Django annotate

I have a table which is having latitude and longitude fields. ` location.objects.annotate( distance =math.fabs(math.pow((math.sin( F('latitude') - float(90.378770)) /2 )),2) + math.cos(90.378770) * math.cos(…
0
votes
1 answer

Can we do arithmetic using Django Subqueries?

I am wondering if Django's ORM allows us to do aggregate operations on subqueires, and then do arithmetic with the resulting values. What would be the proper way to go about something like this: record =…
Adam Starrh
  • 6,428
  • 8
  • 50
  • 89
0
votes
2 answers

convert double to time in python

I have a TimeField() in my django models. I want to convert the sum of the record of this to hours. Here's the actual code in my view: hours_week_decimal = Timesheet.objects.filter(owner = request.user.pk, week =…
Yann Btd
  • 409
  • 2
  • 6
  • 18
0
votes
1 answer

How to extract INT from Queryset

I am trying to create a graph that dynamically updates based on date and count of POs. Model: class JobOrder(models.Model): status = models.CharField('status', choices=STATUS, max_length=200, default="Waiting") job_order =…
0
votes
1 answer

Django Subquery returns only the first element

This is a simplified version of the models: class Toy(models.Model): #generic fields class Order(models.Model): customer = models.ForeignKey(Customer) class OrderItem(models.Model): order = models.ForeignKey(Order) toy =…
panosl
  • 1,709
  • 2
  • 12
  • 15
0
votes
1 answer

Sum of Subquery fields django

I have the following subquery: Subquery( ContestTaskRelationship.objects.filter( contest=contest, solved=OuterRef('id') ).values('cost').all() ) I need then to annotate my QuerySet with sum of cost values…
pomo_mondreganto
  • 2,028
  • 2
  • 28
  • 56
0
votes
1 answer

Django strange behaviour of aggregation over custom ManyToMany field

I've encountered some unexpected (for me) behavior of aggregation over ManyToMany field in django. I have the following schema: class ContestTaskRelationship(models.Model): contest = models.ForeignKey('Contest', on_delete=models.CASCADE) …
pomo_mondreganto
  • 2,028
  • 2
  • 28
  • 56
0
votes
1 answer

Filtered annotations without removing results

Consider a model and a query using annotations, for example the following example from the Django…
nip3o
  • 3,346
  • 4
  • 24
  • 29
0
votes
2 answers

Exclude some Posts from count of tags

I'm using django-taggit to manage my tag. I want to include a list of used tags with the indication of how many times each of them has been used. To do so I'm using taggit_templatetags2 but I can avoid. My models.py: from taggit.managers import…
fabio
  • 1,210
  • 2
  • 26
  • 55
0
votes
2 answers

Group By each date in Django 2

I have a model called Log which has a datetime field created_at. What I want to do is to calculate the number of Logs for each date. I tried to do this: from django.db.models.functions import…
0
votes
1 answer

Aggregate feeds and grab image using Django

Im currently have some website running Drupal, using Feeds Image Grabber module (http://drupal.org/project/feeds_imagegrabber) Because I has started learning Django, I'm trying to look what tools available in Django which can give same functionality…
0
votes
1 answer

Django Queryset - How do I do math on related models with prefetch_related?

I have three models: class Variety(models.Model) name = models.CharField(max_length=24) class Item(models.Model) name = models.CharField(max_length=24) in_stock = models.IntegerField() class ItemPart(models.Model) variety =…
Adam Starrh
  • 6,428
  • 8
  • 50
  • 89