Opened 9 years ago
Closed 9 years ago
#27482 closed Cleanup/optimization (fixed)
Conditional Expressions documentation should have an example for filter() methods
| Reported by: | Daniel Spajic | Owned by: | Jonatas CD |
|---|---|---|---|
| Component: | Documentation | Version: | dev |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Accepted | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | yes | UI/UX: | no |
Description
There's no example on this page for using Case() inside a filter() method. There should be one, since the page clearly says "Conditional expressions let you use if ... elif ... else logic within filters, annotations, aggregations, and updates."
This is the documentation: https://docs.djangoproject.com/en/1.10/ref/models/conditional-expressions/
Change History (5)
comment:1 by , 9 years ago
| Easy pickings: | set |
|---|---|
| Needs documentation: | set |
| Triage Stage: | Unreviewed → Accepted |
| Version: | 1.10 → master |
comment:2 by , 9 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
comment:4 by , 9 years ago
| Needs documentation: | unset |
|---|
Note:
See TracTickets
for help on using tickets.
Example from IRC. Note the logic isn't correct, but the syntax works fine.
Model.objects.filter(date_from__gte=Case( When(Q(has_flexible_departure=True), then=house.available_from), When(Q(has_flexible_departure=False), then=house.available_from), ))