Changes between Initial Version and Version 1 of Ticket #29911
- Timestamp:
- Nov 1, 2018, 10:41:24 AM (6 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #29911
- Property Summary Standardize delete_cached_value API on model Fields → Standardize `delete_cached_value API` on model Fields
-
Ticket #29911 – Description
initial v1 1 I created a custom Django model field that is expensive to calculate and I store a cached value on the model. I am not able to clear the cache when some uses the refresh_from_db() method though, since there is no standard API to hook into it. It appears that there is a custom behavior for ForeignKey that calls the delete_cached_value function, if it detects it's a ForeignKey1 I created a custom Django model field that is expensive to calculate and I store a cached value on the model. I am not able to clear the cache when some uses the `refresh_from_db()` method though, since there is no standard API to hook into it. It appears that there is a custom behavior for `ForeignKey` that calls the `delete_cached_value` function, if it detects it's a `ForeignKey` 2 2 3 3 https://github.com/django/django/blob/master/django/db/models/base.py#L569 4 4 5 It would be great to allow any custom Field to implement `delete_cached_value` and have it called inside refresh_from_db. What are your thoughts? I would be happy to submit a PR if this seems reasonable5 It would be great to allow any custom Field to implement `delete_cached_value` and have it called inside `refresh_from_db`. What are your thoughts? I would be happy to submit a PR if this seems reasonable