3 ms·
GeneratedField looks interesting, but I'm not _really_ sure what gains I get over just calling annotate() on my queryset with some computed fields. At least on
by cdcarter 3y ago
GeneratedField looks interesting, but I'm not _really_ sure what gains I get over just calling annotate() on my queryset with some computed fields. At least on the backends where the computed GeneratedField isn't stored.
- radus 3y agoIt's easier to re-use if you need the same generated field in multiple places.
- cdcarter 3y agoI've been in the habit of replacing the default manager for my model with one with an annotated query set. that way, any Model.objects.all() call will have the computed fields. I find this pretty easy to get used to and re-use. though I do admit I like them defined as actual model-fields with verbose names etc...
- OJFord 3y agoIt's a generated column in the database, vs. annotate is just a python alias for something you're selecting in the query.
- tmnvix 3y agoActually having the derived data in the database would be helpful for simplifying something like a website search implementation. I know I could have used it last month!