Skip to content

Commit

Permalink
Merge pull request django-parler#52 from cdelafuen/patch-1
Browse files Browse the repository at this point in the history
Fixed cache.py bug and test
  • Loading branch information
vdboor committed Dec 15, 2014
2 parents cd36852 + 9ed8253 commit ab76f3a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion parler/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def get_translation_cache_key(translated_model, master_id, language_code):
"""
# Always cache the entire object, as this already produces
# a lot of queries. Don't go for caching individual fields.
return 'parler.{0}.{1}.{2}.{3}'.format(translated_model._meta.app_label, translated_model.__name__, long(master_id), language_code)
return 'parler.{0}.{1}.{2}.{3}'.format(translated_model._meta.app_label, translated_model.__name__, master_id, language_code)


def get_cached_translation(instance, language_code=None, related_name=None, use_fallback=False):
Expand Down
10 changes: 9 additions & 1 deletion parler/tests/model_construction.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.core.cache import cache
from django.db.models import Manager
from .utils import AppTestCase
from .testapp.models import ManualModel, ManualModelTranslations, SimpleModel, Level1, Level2, ProxyBase, ProxyModel, DoubleModel, RegularModel
from .testapp.models import ManualModel, ManualModelTranslations, SimpleModel, Level1, Level2, ProxyBase, ProxyModel, DoubleModel, RegularModel, CharModel


class ModelConstructionTests(AppTestCase):
Expand Down Expand Up @@ -90,3 +90,11 @@ def test_overlapping_proxy_model(self):

# Refetch from db, should raise an error.
self.assertRaises(RuntimeError, lambda: RegularModelProxy.objects.all()[0])


def test_model_with_different_pks(self):
"""
Test that TranslatableModels works with different types of pks
"""
self.assertIsInstance(SimpleModel.objects.create(tr_title='Test'), SimpleModel)
self.assertIsInstance(CharModel.objects.create(pk='test', tr_title='Test'), CharModel)
8 changes: 8 additions & 0 deletions parler/tests/testapp/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,11 @@ class DoubleModelMoreTranslations(TranslatedFieldsModel):
class RegularModel(models.Model):
# Normal model without translations. Test how replacing the field works.
original_field = models.CharField(default="untranslated", max_length=255)


class CharModel(TranslatableModel):
id = models.CharField(max_length=45, primary_key=True)

class CharModelTranslation(TranslatedFieldsModel):
master = models.ForeignKey(CharModel)
tr_title = models.CharField(max_length=200)

0 comments on commit ab76f3a

Please sign in to comment.