Changes between Initial Version and Version 1 of Ticket #28822, comment 6


Ignore:
Timestamp:
Mar 12, 2020, 3:07:53 AM (5 years ago)
Author:
Matthijs Kooijman

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #28822, comment 6

    initial v1  
    22
    33 - These annotations can be enabled using an automatic mechanism on a queryset (e.g. `qs.add_annotation('foo')`).
    4  - These annotations can be automatically enabled by using them in a filter, another annotation, etc., e.g. `qs.filter(foo__gt=1)` would load the `foo` annotation automatically, instead of having to do `qs.add_foo().filter(foo__gt=1)`. This is especially powerful when used in cross-relation lookups, where it is (AFAIK) not normally possible to add annotations on a related model.
     4 - These annotations can be automatically enabled by using them in a filter, another annotation, etc., e.g. `qs.filter(foo__gt=1)` would load the `foo` annotation automatically, instead of having to do `qs.add_foo().filter(foo__gt=1)`.
    55 - These annotations can also be explicitly referenced and resolved to their query expression, for use as part of other expressions, queries, etc. I'm not entirely sure how this could be used yet, but I have the suspicion that making annotations named objects (outside of model instances) would allow for more reuse and composition.
     6
     7For the last two points, I can see particular merit in situations where you cannot currently specify a custom queryset, such as cross-relation lookups, conditions on constraints, aggregrations, `FilteredRelation`, etc.
    68
    79I originally also saw great merit in being able to calculate annotations in Python if they were not calculated during the query already (since this, in some cases, can remove the need to decide which annotations are needed beforehand). However, as extensively debated in the thread linked above this would have problems wrt performance (e.g. having to do subqueries or joins in Python) and correctness (subtle differences in database and Python handling of calculations), so I'm not so sure whether this would be feasible (but also less needed, if managing annotations is easier).
Back to Top