#36218: allow annotate to override model's fields
-------------------------------------+-------------------------------------
Reporter: Jan Napieralski | Type: New
| feature
Status: new | Component: Database
| layer (models, ORM)
Version: 5.1 | Severity: Normal
Keywords: QuerySet.extra | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
I want to modify the QuerySet field such that it is fetched from DB and
its real field is redacted. For example fetching some employee data, but
replacing all the emails and phone numbers to NULL's because of some
security or role flag in the API resolver for this
Currently the .annotate() method doesn't allow for the overlap of output
field with model field. I have seen, that the way to handle it is to call
.values() excluding the overwritten field, but in the large models with
many fields or queries with joins, its not realistically possible to know
what fields will be used when doing this QuerySet manipulation. The
.deffer() doesn't work neither
I propose some flag to the .annotate() for allowing to overlap and
essentially overwrite the model field, bc currently the only way without
evaluating it, is the .extra()
--
Ticket URL: <
https://code.djangoproject.com/ticket/36218>
Django <
https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.