fahadalmutairi
fahadalmutairi

Reputation: 43

django-parler doesn't show tabs in admin

For some reason I'm not seeing any language tabs when adding to the admin. I'm using Django 1.9.10. I was using django-hvad but decided to try parler. I have tried the same exact code in a fresh project and it worked but in my existing project it doesn't. Please note that I'm also using django-mptt. Tried parler in a separate model from the mptt model and vice versa.

settings/base.py

# Translations
gettext = lambda s: s
LANGUAGES = (
    ('en', gettext('English')),
    ('ar', gettext('Arabic')),
)

LOCALE_PATHS = (
    os.path.join(BASE_DIR, "locale"),
)

# # Parler Configuration
PARLER_LANGUAGES = {
    None: (
        {'code': 'ar', },
        {'code': 'en',},
    ),
    'default': {
        'fallback': 'ar',             # defaults to PARLER_DEFAULT_LANGUAGE_CODE
        'hide_untranslated': False,   # the default; let .active_translations()       return fallbacks too.
    }
}
PARLER_DEFAULT_LANGUAGE_CODE = 'ar'

Model

class Category(MPTTModel, TranslatableModel):
    slug = models.SlugField(max_length=50, unique=True, null=True, blank=True)
    translations = TranslatedFields(
        title = models.CharField(max_length=90, unique=True, null=True, blank=True)
    )
    timestamp = models.DateTimeField(auto_now_add=True, auto_now=False)
    parent = TreeForeignKey('self', null=True, blank=True, related_name='children')

    objects = CategoryManager()

    def __unicode__(self):

        return unicode(self.slug) or u''

    def get_absolute_url(self):
        return reverse("category:detail", kwargs={"slug": self.slug})

    class Meta:
        ordering = ["slug"]
        verbose_name = _("Category")
        verbose_name_plural = _("Categories")

admin.py

class CategoryAdminForm(MPTTAdminForm, TranslatableModelForm):
    pass


class CategoryAdmin(TranslatableAdmin, MPTTModelAdmin):
    form = CategoryAdminForm

    def get_prepopulated_fields(self, request, obj=None):
        return {'slug': ('title',)}  # needed for translated fields


admin.site.register(Category, CategoryAdmin)

Upvotes: 3

Views: 2370

Answers (2)

Whit
Whit

Reputation: 191

I've just spent a lot of time to fix same problem. Try to use real SITE_ID instead of None:

PARLER_LANGUAGES = {
    1: (
        {'code': 'ar', },
        {'code': 'en',},
    ),
    'default': {
        'fallback': 'ar',             # defaults to PARLER_DEFAULT_LANGUAGE_CODE
        'hide_untranslated': False,   # the default; let .active_translations()       return fallbacks too.
    }
}

Upvotes: 19

Peterino
Peterino

Reputation: 16757

Try upgrading to latest django-parler.

We had the same issue with Parler 1.5.1 and Django 1.8.14. Upgrading to django-parler==1.6.5 and Django==1.8.15 made the translation tabs show up in the Admin again.

Upvotes: 0

Related Questions