Closed pyzenberg closed 3 months ago
This is a Wagtail core issue. WIP PR - https://github.com/wagtail/wagtail/pull/9390
Flagging that an issue has been raised to track this request. Any input (clarity on use cases, desire to sponsor or contribute) should be added to the issue.
Closing as this is a core matter
Sorry for the late reply as I opened the issue first. I think I found the answer to my own question later.
Here is the shortened code snippet:
from django.conf import settings
from django.db import models
from django.utils.translation import gettext as _, get_language
from modelcluster.models import ClusterableModel
from wagtail.admin.panels import FieldPanel, MultiFieldPanel, TabbedInterface
from wagtail.contrib.settings.models import BaseGenericSetting
from wagtail.contrib.settings.registry import register_setting
@register_setting
class LocalizedConfig(BaseGenericSetting, ClusterableModel):
language_code = models.CharField(
_('language'),
max_length=2,
unique=True,
)
# social network tab
twitter = models.URLField(_('Twitter'), blank=True)
youtube = models.URLField(_('Youtube'), blank=True)
instagram = models.URLField(_('Instagram'), blank=True)
_tab_socials = [
FieldPanel('twitter'),
FieldPanel('youtube'),
FieldPanel('instagram'),
]
panels = [
TabbedInterface([
MultiFieldPanel(_tab_socials, heading=_('Social Networks')),
]),
]
class Meta:
verbose_name = _('Localized Configuration')
def save(self, *args, **kwargs):
if not self.language_code:
self.language_code = get_language() or settings.LANGUAGE_CODE
super().save(*args, **kwargs)
@classmethod
def base_queryset(cls):
queryset = cls.objects.filter(language_code=get_language())
if cls.select_related is not None:
queryset = queryset.select_related(*cls.select_related)
return queryset
#
And here is the full code. I was used Wagtail 4.2.1 then. Hope it help.
Thank you @pyzenberg
How can I separate the site settings for each language? For example, separate Twitter accounts for each language and...