Tax rule editor: Use cacehd countries

This commit is contained in:
Raphael Michel
2020-12-11 15:19:34 +01:00
parent a665836a60
commit 2cd5094393
2 changed files with 6 additions and 2 deletions

View File

@@ -6,6 +6,7 @@ from django_countries.fields import CountryField
class CachedCountries(Countries):
_cached_lists = {}
cache_subkey = None
def __iter__(self):
"""
@@ -14,6 +15,8 @@ class CachedCountries(Countries):
slow.
"""
cache_key = "countries:all:{}".format(get_language())
if self.cache_subkey:
cache_key += ":" + self.cache_subkey
if cache_key in self._cached_lists:
yield from self._cached_lists[cache_key]
return