Opened 8 years ago
Closed 8 years ago
#27841 closed New feature (duplicate)
ORM 'join on' with extra restrictions
Description ¶
My use case is a budget app. I have the following:
class Category
class Transaction
date: date
amount: decimal
category: manytomany(Category, through=Split)
I need to get all categories with the amount spent in a month, even if no money was spent in that category for the month. My SQL solution is to "LEFT OUTER JOIN transaction ON (split.transaction_id = transaction.id and date between <earliest> and <latest>)", then I can get the sum of "transactionamount". Every Django ORM solution I've tried will return only the categories with at least one transaction during the month, so I'm missing a bunch of categories when the month starts.
I'm going to use extra or raw until I can figure out a better way to get the results I want. I was told (by https://docs.djangoproject.com/en/1.10/ref/models/querysets/) to open a ticket to tell you about my legitimate usage.
Change History (2)
comment:1 by , 8 years ago
Keywords: | QuerySet.extra added |
---|
comment:2 by , 8 years ago
Resolution: | → duplicate |
---|---|
Status: | new → closed |
Duplicate of #27332.