I have a site which is i18n enabled and using wagtail-localize
. When editing (or creating) the original language of a page, all the snippets show values for every language, if you use the standard FieldPanel
. Using the SnipperChooserPanel is not an option because there are a lot of ParentalManytoManyField
s in the model, it would be too cluttered for the editors.
This is how the model and snippet is constructed.
@register_snippet
class Level(TranslatableMixin):
name = models.CharField(max_length=255)
def __str__(self):
return self.name
class Meta:
verbose_name = "Educational Level"
unique_together = ('translation_key', 'locale')
class Activity(Page):
...
level = ParentalManyToManyField(Level, verbose_name='Education level', blank=True)
MultiFieldPanel([
....
FieldPanel('level', widget=forms.CheckboxSelectMultiple),
])
I'm trying to work out how to subclass FieldPanel
so it uses the page's locale to filter the snippet queryset.
I have hacky/temporary solution to this using the limit_choices_to
kwarg for ParentalManyToManyField
but I can only filter by the user language not the page language.
def limit_lang_choice():
limit = models.Q(locale__language_code=get_language())
return limit