from django.conf import settings
from django.core.cache import cache
from django.db import models
from django.utils.decorators import classproperty
from taggit.managers import TaggableManager

from translator.util import get_key


class TranslationBase(models.Model):
    key = models.CharField(max_length=255, unique=True)
    description = models.TextField()

    tags = TaggableManager(blank=True)

    class Meta:
        abstract = True

    def __unicode__(self):
        return self.key

    def save(self, force_insert=False, force_update=False, using=None, update_fields=None):
        all_translation_keys = self.__class__.objects.all().values_list('key', flat=True)
        for l in settings.LANGUAGES:
            cache.delete_many([get_key(l[0], k, self.cache_key_prefix) for k in all_translation_keys])
        return super().save(force_insert, force_update, using, update_fields)

    @classproperty
    def cache_key_prefix(self):
        """To separate cache keys, we need to specify a unique prefix per model."""
        return self._meta.db_table


class Translation(TranslationBase):
    pass

from django.conf import settings
from django.core.cache import cache
from django.db import models
from taggit.managers import TaggableManager

from translator.util import get_key

try:
    # Django 3.1 and above
    from django.utils.functional import classproperty
except ImportError:
    from django.utils.decorators import classproperty


class TranslationBase(models.Model):
    key = models.CharField(max_length=255, unique=True)
    description = models.TextField()

    tags = TaggableManager(blank=True)

    class Meta:
        abstract = True

    def __unicode__(self):
        return self.key

    def save(self, force_insert=False, force_update=False, using=None, update_fields=None):
        all_translation_keys = self.__class__.objects.all().values_list('key', flat=True)
        for l in settings.LANGUAGES:
            cache.delete_many([get_key(l[0], k, self.cache_key_prefix) for k in all_translation_keys])
        return super().save(force_insert, force_update, using, update_fields)

    @classproperty
    def cache_key_prefix(self):
        """To separate cache keys, we need to specify a unique prefix per model."""
        return self._meta.db_table


class Translation(TranslationBase):
    pass

Update import for classproperty in django 3.1 and above
Update import for classproperty in django 3.1 and above

  from django.conf import settings
  from django.core.cache import cache
  from django.db import models
- from django.utils.decorators import classproperty
  from taggit.managers import TaggableManager
  
  from translator.util import get_key
+ 
+ try:
+     # Django 3.1 and above
+     from django.utils.functional import classproperty
+ except ImportError:
+     from django.utils.decorators import classproperty
  
  
  class TranslationBase(models.Model):
      key = models.CharField(max_length=255, unique=True)
      description = models.TextField()
  
      tags = TaggableManager(blank=True)
  
      class Meta:
          abstract = True
  
      def __unicode__(self):
          return self.key
  
      def save(self, force_insert=False, force_update=False, using=None, update_fields=None):
          all_translation_keys = self.__class__.objects.all().values_list('key', flat=True)
          for l in settings.LANGUAGES:
              cache.delete_many([get_key(l[0], k, self.cache_key_prefix) for k in all_translation_keys])
          return super().save(force_insert, force_update, using, update_fields)
  
      @classproperty
      def cache_key_prefix(self):
          """To separate cache keys, we need to specify a unique prefix per model."""
          return self._meta.db_table
  
  
  class Translation(TranslationBase):
      pass
  
Update import for classproperty in django 3.1 and above
## Code Before:
from django.conf import settings
from django.core.cache import cache
from django.db import models
from django.utils.decorators import classproperty
from taggit.managers import TaggableManager

from translator.util import get_key


class TranslationBase(models.Model):
    key = models.CharField(max_length=255, unique=True)
    description = models.TextField()

    tags = TaggableManager(blank=True)

    class Meta:
        abstract = True

    def __unicode__(self):
        return self.key

    def save(self, force_insert=False, force_update=False, using=None, update_fields=None):
        all_translation_keys = self.__class__.objects.all().values_list('key', flat=True)
        for l in settings.LANGUAGES:
            cache.delete_many([get_key(l[0], k, self.cache_key_prefix) for k in all_translation_keys])
        return super().save(force_insert, force_update, using, update_fields)

    @classproperty
    def cache_key_prefix(self):
        """To separate cache keys, we need to specify a unique prefix per model."""
        return self._meta.db_table


class Translation(TranslationBase):
    pass

## Instruction:
Update import for classproperty in django 3.1 and above
## Code After:
from django.conf import settings
from django.core.cache import cache
from django.db import models
from taggit.managers import TaggableManager

from translator.util import get_key

try:
    # Django 3.1 and above
    from django.utils.functional import classproperty
except ImportError:
    from django.utils.decorators import classproperty


class TranslationBase(models.Model):
    key = models.CharField(max_length=255, unique=True)
    description = models.TextField()

    tags = TaggableManager(blank=True)

    class Meta:
        abstract = True

    def __unicode__(self):
        return self.key

    def save(self, force_insert=False, force_update=False, using=None, update_fields=None):
        all_translation_keys = self.__class__.objects.all().values_list('key', flat=True)
        for l in settings.LANGUAGES:
            cache.delete_many([get_key(l[0], k, self.cache_key_prefix) for k in all_translation_keys])
        return super().save(force_insert, force_update, using, update_fields)

    @classproperty
    def cache_key_prefix(self):
        """To separate cache keys, we need to specify a unique prefix per model."""
        return self._meta.db_table


class Translation(TranslationBase):
    pass
