diff --git a/example/article/admin.py b/example/article/admin.py index 22455ec7..324c439f 100644 --- a/example/article/admin.py +++ b/example/article/admin.py @@ -31,7 +31,7 @@ class ArticleAdmin(TranslatableAdmin): form = ArticleAdminForm # NOTE: when using Django 1.4, use declared_fieldsets= instead of fieldsets= - declared_fieldsets = ( + fieldsets = ( (None, { 'fields': ('title', 'slug', 'published', 'category'), }), diff --git a/example/article/urls.py b/example/article/urls.py index a82e08b3..574e9a61 100644 --- a/example/article/urls.py +++ b/example/article/urls.py @@ -1,7 +1,7 @@ -from django.conf.urls import * +from django.conf.urls import url from .views import ArticleListView, ArticleDetailView -urlpatterns = patterns('', +urlpatterns = [ url(r'^$', ArticleListView.as_view(), name='article-list'), url(r'^(?P[^/]+)/$', ArticleDetailView.as_view(), name='article-details'), -) +] diff --git a/parler/fields.py b/parler/fields.py index f101ecbd..47a90927 100644 --- a/parler/fields.py +++ b/parler/fields.py @@ -10,6 +10,8 @@ indicate that the derived model is expected to provide that translatable field. """ from __future__ import unicode_literals + +import django from django.forms.forms import pretty_name @@ -136,7 +138,12 @@ def short_description(self): # Fallback to what the admin label_for_field() would have done otherwise. return pretty_name(self.field.name) - return translations_model._meta.get_field_by_name(self.field.name)[0].verbose_name + if django.VERSION >= (1, 8): + field = translations_model._meta.get_field(self.field.name) + else: + field = translations_model._meta.get_field_by_name(self.field.name)[0] + + return field.verbose_name class LanguageCodeDescriptor(object): diff --git a/parler/tests/test_admin.py b/parler/tests/test_admin.py index 5ca84cfd..35d0963e 100644 --- a/parler/tests/test_admin.py +++ b/parler/tests/test_admin.py @@ -13,17 +13,11 @@ class AdminTests(AppTestCase): """ def test_list_label(self): - # Ensure model data is correct - self.assertEqual(SimpleModel._parler_meta.root_model._meta.get_field_by_name('tr_title')[0].verbose_name, "Translated Title") - # See that adding a field to the admin list_display also receives the translated title # This happens by TranslatedFieldDescriptor.short_description self.assertEqual(label_for_field('tr_title', SimpleModel), "Translated Title") def test_list_label_abc(self): - # Ensure model data is correct - self.assertEqual(ConcreteModel._parler_meta.root_model._meta.get_field_by_name('tr_title')[0].verbose_name, "Translated Title") - # See that the TranslatedFieldDescriptor of the concrete model properly routes to the proper model self.assertEqual(label_for_field('tr_title', ConcreteModel), "Translated Title") diff --git a/runtests.py b/runtests.py index 01a119df..e6cf07a6 100755 --- a/runtests.py +++ b/runtests.py @@ -10,6 +10,40 @@ sys.path.insert(0, path.join(module_root, 'example')) + if django.VERSION >= (1, 8): + template_settings = dict( + TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': (), + 'OPTIONS': { + 'loaders': ( + 'django.template.loaders.filesystem.Loader', + 'django.template.loaders.app_directories.Loader', + ), + 'context_processors': ( + 'django.template.context_processors.debug', + 'django.template.context_processors.i18n', + 'django.template.context_processors.media', + 'django.template.context_processors.request', + 'django.template.context_processors.static', + 'django.contrib.auth.context_processors.auth', + ), + }, + }, + ] + ) + else: + template_settings = dict( + TEMPLATE_LOADERS = ( + 'django.template.loaders.app_directories.Loader', + 'django.template.loaders.filesystem.Loader', + ), + TEMPLATE_CONTEXT_PROCESSORS = list(default_settings.TEMPLATE_CONTEXT_PROCESSORS) + [ + 'django.core.context_processors.request', + ], + ) + settings.configure( DEBUG = False, # will be False anyway by DjangoTestRunner. TEMPLATE_DEBUG = True, @@ -26,13 +60,6 @@ 'LOCATION': 'unique-snowflake', } }, - TEMPLATE_LOADERS = ( - 'django.template.loaders.app_directories.Loader', - 'django.template.loaders.filesystem.Loader', - ), - TEMPLATE_CONTEXT_PROCESSORS = list(default_settings.TEMPLATE_CONTEXT_PROCESSORS) + [ - 'django.core.context_processors.request', - ], INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', @@ -66,6 +93,7 @@ 'fallbacks': ['en'], }, }, + **template_settings )