Skip to content

Commit

Permalink
Generic relation has no method get_cache_name therefore refresh_from_…
Browse files Browse the repository at this point in the history
…db does not work for it
  • Loading branch information
matllubos committed Jan 17, 2019
1 parent ae82ff6 commit 7fb5fc3
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions chamber/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,8 +455,11 @@ def refresh_from_db(self, *args, **kwargs):

if StrictVersion(django.get_version()) < StrictVersion('2.0'):
for field in [f for f in self._meta.get_fields() if f.is_relation]:
if field.get_cache_name() in self.__dict__:
del self.__dict__[field.get_cache_name()]
# For Generic relation related model is None
# https://docs.djangoproject.com/en/2.1/ref/models/meta/#migrating-from-the-old-api
cache_key = field.get_cache_name() if field.related_model else field.cache_attr
if cache_key in self.__dict__:
del self.__dict__[cache_key]

return self

Expand Down

0 comments on commit 7fb5fc3

Please sign in to comment.