Questions tagged [django-annotate]

297 questions
0
votes
1 answer

Invalid distinct with django

I try to get a cars list on my Django project but i'm in trouble with ORM class Car(models.Model): name = models.CharField(max_length=200) owner = models.ForeignKey(User) With Car.objects.all() I have a list as: - car#1, user#1 - car#1,…
0
votes
1 answer

Django annotate single instance of many-2-many field using 'when' on other fields of the instnce

I have a somewhat complicated model, so I will do my best to give an example that simplifies my current state, and my need. I have a queryset: qs = MyModel.objects.all() Each instance in this queryset, has a many-2-many field to another model,…
orizis
  • 166
  • 2
  • 15
0
votes
2 answers

Django sharing anotations between related Items

Consider a room booking system. You might have a Building, Floor, Room models as well as a Booking. We give the room a name based on its building and floor: class Room(models.Model): number = models.PositiveIntegerField() name =…
Oli
  • 235,628
  • 64
  • 220
  • 299
0
votes
1 answer

Annotate number of identical items in manager

Let's say I have following simplified model: class CurrentInvoices(models.Manager): def get_queryset(self): qs = super(CurrentInvoices, self).get_queryset() current_invoices = qs.order_by('person',…
SaeX
  • 17,240
  • 16
  • 77
  • 97
0
votes
1 answer

How to annotate count filtered on datetime?

I've got Categories and Items. The items have an end field (datetime). Now I need to list all categories and display the related item count and the item count of items in the future. As an example: Cat Foo, 2 items, 1 in the future. Cat n, n items…
allcaps
  • 10,945
  • 1
  • 33
  • 54
-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 get annotated attributes in a template from a DetailView?

I'm working on a small e-commerce. For a model 'Product' I keep track of the stock using a Custom Manager and a method called Products.objects.with_stock() that uses annotations (I'm required to do so, there's no way I can add a stock attribute in…
-1
votes
1 answer

Annotate + Distinct Not Implemented, Count a Distinct Subquery

I have two models, RetailLocation and Transaction, which share a one-to-many relationship respectively. I trying to annotate the total number of days (Count) a RetailLocation has any number of Transactions for. In doing so, I am filtering the…
hEX90
  • 21
  • 4
-1
votes
1 answer

how make a conditions in django annotate?

i'm, trying to do something like this : c = if x > y return x else return y inner annotate function class factura (models.MODEL): price = Model.integerField(max_length=50, null=False) articles = Models.charField(Max_length=50, default=0,…
-1
votes
1 answer

Django annotate on float field is not working properly

I'm using Django 2.2 I have the following model structure class Location(models.Model): name = models.CharField(max_length=200) country_name = models.CharField(max_length=200) latitude = models.FloatField(null=True, blank=True) longitude =…
Anuj TBE
  • 9,198
  • 27
  • 136
  • 285
-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…
-1
votes
1 answer

Using related models with conditional expression

Goal: use a related model attribute as a filter inside a conditional expression for an annotation. I'm currently adding some functionality to an old Django app, this app has some design issues and i have nothing to do with it. After some research I…
1 2 3
19
20