#35269: GeneratedFields can't be defined on RelatedFields
-------------------------------------+-------------------------------------
Reporter: Perrine L. | Owner: nobody
Type: New feature | Status: closed
Component: Database layer | Version: 5.0
(models, ORM) |
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Marco Glauser):
We ran into the same issue. We tried to switch the responsible user of a
task depending on some simple business logic that could be evaluated by
the GeneratedField.
The ForeignObject approach is working for us.
For anyone stumbling on this discussion later on, we observed a caching
issue with ForeignObject. The cache of the field doesn't get refreshed
when `refresh_from_db` gets called.
We had to explicitly override `refresh_from_db` on the Task model
{{{
def refresh_from_db(self, using=None, fields=None):
super(Task, self).refresh_from_db(using=using, fields=fields)
responsible_user_field = self._meta.get_field("responsible_user")
if responsible_user_field.is_cached(self):
responsible_user_field.delete_cached_value(self)
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/35269#comment:9>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/0107019025d07946-de482054-8847-45c6-b499-f6de6a44b916-000000%40eu-central-1.amazonses.com.