Add support for using F() expressions in CounterField initialization.
Review Request #6242 — Created Aug. 18, 2014 and submitted
CounterField intializers can now return a F() expression in the
initializer function, or provide the expression instead of a function,
instead of returning a numeric value. These will be passed to the
database query, allowing for atomic computation of initial counter
state.Since we didn't have unit tests for CounterField before, this comes with
a set of tests for the new functionality and much of the original
functionality.
Unit tests pass.
- Change Summary:
-
Expressions are now allowed on new instances. In this case, they'll just result in
0
instead of an error, which I think makes sense, since no relations will be populated at this point. - Commit:
-
bec8800a4297bf256581d38c8d7d0619a714015c8ccfa0d2d3b5f0b2931c1216de537d1d3750bf7c
- Diff:
-
Revision 2 (+179 -4)
- Change Summary:
-
Fixed Review Bot issues, and an improperly referenced class in a test (same result either way, but used the wrong class).
- Commit:
-
8ccfa0d2d3b5f0b2931c1216de537d1d3750bf7cd97e1e8e1569ea74c44462b1ff61431595c056e7
- Diff:
-
Revision 3 (+175 -4)
-
Tool: Pyflakes Processed Files: djblets/db/fields.py djblets/db/tests.py Tool: PEP8 Style Checker Processed Files: djblets/db/fields.py djblets/db/tests.py
-
Bah.. There are issues with this. Django doesn't allow aggregates when updating.
I'll be toying with some other changes and then update this with some new code.
- Change Summary:
-
- Unit tests now actually test real-world database usage.
- Aggregates are no longer supported. Turns out that they don't really work in Django for
update()
calls. The real unit tests caught this. F()
expressions can now be set as the initializer, instead of having to be returned by the initializer.
- Summary:
-
Add support for using F() and aggregates in CounterField initialization.Add support for using F() expressions in CounterField initialization.
- Description:
-
~ CounterField intializers can now return a F() expression or an aggregate
~ (like Count()) instead of a numeric value. These will be passed to the ~ CounterField intializers can now return a F() expression in the
~ initializer function, or provide the expression instead of a function, + instead of returning a numeric value. These will be passed to the database query, allowing for atomic computation of initial counter state. Since we didn't have unit tests for CounterField before, this comes with
a set of tests for the new functionality and much of the original functionality. - Commit:
-
d97e1e8e1569ea74c44462b1ff61431595c056e74d686a1a9e98979153fac7043fc286d8985f162e