Hi Matt,
sorry for the late reply. This is exactly what I was looking for!
However, if I understand correctly this is more a proof of concept and
not ready for production use. There still seem to be some subtlties that
need to be fixed:
- related queries with shared_property
- filtered aggregates (e.g. Max('name', filter=Q(…)) in related queries
with ComputedField (Q object would need similar processing to F objects)
- group_by with both implementations (I get "aggregate functions are not
allowed in the GROUP BY clause")
Other than that it is great to see this is possible as a third party
library. I am still not sure how much interest there actually is though.
tobias
PS: There is a small typo in the first link in your blog post.
On 15/03/2021 04.49, schinckel wrote:
Hi Tobias.
I've done a bit of stuff on this, and found there were actually limited
changes that need to be made to django to got this to work.
https://schinckel.net/2020/09/15/django-properties-from-expressions%2C-or-computedfield-part-2/
I haven't touched it much since then (although I'm keen to revisit it,
actually), but it's actually possible that we can do it without any
changes to Django.
https://github.com/schinckel/django-shared-property
Matt.
On Sunday, March 14, 2021 at 11:46:15 PM UTC+10:30 Tobias Bengfort wrote:
Hi,
a while back there has been a discussion about calculated model fields:
https://groups.google.com/g/django-developers/c/ADSuUUuZp3Q/m/5o02Lp_jCwAJ
<https://groups.google.com/g/django-developers/c/ADSuUUuZp3Q/m/5o02Lp_jCwAJ>
The main benefit would be that these would be available in cases where
annotations are currently not available, e.g. related queries or admin
lists (see #14336).
Note that the topic of fields that have both a DB and python
implementation was discussed and the consensus was that the python
equivalents could be added by a separate library, if required. So I am
only talking about the database part here.
The linked discussion was mainly about *what* is desired, not *how* it
could be done. I also noticed that the fellows did not participate in
that discussion.
I would like to have a shot at this topic. So I am interested in:
- Do you think this is even possible/worth the effort?
- How could this be implemented and what would be potential challenges?
- Is it possible to implement this in a third party library or does it
require changes to django itself?
I would probably start with a non-editable, non-concrete model field
(similar to GenericForeignKey or ForeignObjRel). But I have no clue yet
how to integrate that with QuerySet/Query.
thanks
tobias
--
You received this message because you are subscribed to the Google
Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to django-developers+unsubscr...@googlegroups.com
<mailto:django-developers+unsubscr...@googlegroups.com>.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-developers/8d325f4e-9c20-4268-9c46-6f682911ac5dn%40googlegroups.com
<https://groups.google.com/d/msgid/django-developers/8d325f4e-9c20-4268-9c46-6f682911ac5dn%40googlegroups.com?utm_medium=email&utm_source=footer>.
--
You received this message because you are subscribed to the Google Groups "Django
developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to django-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-developers/bf68d4a3-dcbc-a411-66cd-2197bc53b0ba%40posteo.de.