由於某些原因,我在添加到管理員時看不到任何語言選項卡。我正在使用Django 1.9.10。我正在使用django-hvad,但決定試用parler。我在一個新項目中嘗試了相同的確切代碼,但它在我現有的項目中沒有。請注意,我也在使用django-mptt。在與mptt模型不同的模型中嘗試了parler,反之亦然。django-parler不顯示管理員標籤
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'
型號
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)
我改變了'PARLER_LANGUAGES'指數從'1'到'2',因爲我已經有'SITE_ID = 2',SITE_ID是翻譯選項卡中顯示管理問題界面,很好的回答你解決了我的問題。 –