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

unsupported operand type(s) for +: 'NoneType' and 'NoneType'

How can I handle this error, its driving me crazy: unsupported operand type(s) for +: 'NoneType' and 'NoneType' Also unsupported operand type(s) for +: 'Float' and 'NoneType' I get what its telling me (I think) so this is the code I wrote to try…
0
votes
0 answers

Multiple joins in annotation

I have a Post model which has ManyToMany relation with User to reflect Likes feature. Moreover Post has ForeignKey relation to itself since each post can be a comment to existing Post (only one depth level is forced - there are no discussion…
0
votes
1 answer

Apply condition in this query in django

I have models like this: class Category(models.Model): user = models.ForeignKey(User) name = models.CharField(max_length=128) budget = models.DecimalField(default=0.0, decimal_places=2, max_digits=8, help_text="Amount in dollars…
pynovice
  • 7,424
  • 25
  • 69
  • 109
0
votes
1 answer

Django: Order query set by comment count

Very simple... I am using Django 1.4.1, and need to order a queryset by the inverse of the number of comments on it. I am using the Django comment framework, and have attempted to use the .annotate(comment_count = Count('comment') structure…
0
votes
1 answer

Efficiency of aggregate and annotate vs signals

I want to count the number of contributions a user made to my site so I can rank them on the site. I managed to write some beautiful code which does exactly that, but on a per user basis. Because the user get's different amounts of points for…
tBuLi
  • 2,295
  • 2
  • 16
  • 16
0
votes
2 answers

Django: using aggregates to show vote counts for basic polls app

I'm making a very basic poll app. It's similar to the one in the Django tutorial but I chose to break out the vote counting aspect into its own model (the tutorial just adds a vote count field alongside each answer). Here's my models: class…
Matt Andrews
  • 2,868
  • 3
  • 31
  • 53
0
votes
1 answer

Django aggregation - Sum of two Sums

Let's assume we have the following two models: class Player(Model): alliance = ForeignKey("Alliance") points = PositiveIntegerField() class Alliance(Model): points = PositiveIntegerField() Every player and every alliance have a…
aemdy
  • 3,702
  • 6
  • 34
  • 49
-1
votes
1 answer

how to take average of every 10 minutes of a model django

I am using multiple APIs and saving them to the database. I have one model called Station (it has a DateTime field and some other fields) and every API is for one station. These APIs come from devices that measure some variables and they get updated…
-1
votes
1 answer

how to compare two fields of different models in Django query-set?

Want to compare(if they are same or not) 'map_id' of 'map' model with 'uni_id' of 'Uni' model, return if they are same. Note: models map and Uni are also in different databases. Below are the two models: class map(models.Model): job_id =…
-1
votes
1 answer

Annotate count of related related filtered objects

I have these models: class Shop(..): category = ForeignKey... class Product(..): shop = ForeignKey... category = ForeignKey... is_active = BooleanField... class Category(..): name = ... I need to annotate the number of active…
-2
votes
1 answer

Performing group by and aggregrate Django

I would like to do an average on a subquery with group by, how should I do this in Django without using raw SQL? See SQL example: SELECT AVG(calories) AS AVG_DAILY_CALORIES FROM ( SELECT date, SUM(calories) FROM products_eaten GROUP BY date )…
Eric Muijs
  • 29
  • 6
1 2 3
13
14