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 ParentalManytoManyFields 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
Turns out the locale is lurking in the
BoundPanel.instanceHere's a select panel that will filter according to locale. It'll match the default panel type for the field, or you can override with an appropriate form widget (one of
CheckboxSelectMultiple,RadioSelect,SelectorSelectMultiple). Settyped_choice_field=Trueto forceSelectinto a dropdown widget (default is a list).So in your Activity class, you'd call this with