wagtail / wagtail-localize

Translation plugin for Wagtail CMS
https://wagtail-localize.org/
Other
226 stars 86 forks source link

error message: get_form_options #585

Closed DBonbon closed 2 years ago

DBonbon commented 2 years ago

Working with wagtail-localize 1.2, wagtail 3, I try to apply a menu snippets. When I try to translate the menu (i.e. after migrations and creating the English menu), I get  the following error:AttributeError at /admin/snippets/cms/menu/edit/8/ 'NoneType' object has no attribute 'get_form_options' Reading the previous issues, it seems that InlinePanal is still an open issue...Though I'm not sure. Can you kindly advise if currently this is possible? If yes, what am I doing wrong?

my code is:

class MenuItem(TranslatableMixin, Orderable):

    link_title = models.CharField(
        blank=True,
        null=True,
        max_length=50
    )
    link_url = models.CharField(
        max_length=500,
        blank=True
    )
    link_page = models.ForeignKey(
        "wagtailcore.Page",
        null=True,
        blank=True,
        related_name="+",
        on_delete=models.CASCADE,
    )
    open_in_new_tab = models.BooleanField(default=False, blank=True)

    page = ParentalKey("Menu", related_name="menu_items")

    panels = [
        FieldPanel("link_title"),
        FieldPanel("link_url"),
        PageChooserPanel("link_page"),
        FieldPanel("open_in_new_tab"),
    ]

    @property
    def link(self):
        if self.link_page:
            return self.link_page.url
        elif self.link_url:
            return self.link_url
        return '#'

    @property
    def title(self):
        if self.link_page and not self.link_title:
            return self.link_page.title
        elif self.link_title:
            return self.link_title
        return 'Missing Title'

@register_snippet
class Menu(TranslatableMixin, ClusterableModel):
    """The main menu clusterable model."""

    title = models.CharField(max_length=100)
    slug = AutoSlugField(populate_from="title", editable=True)
    # slug = models.SlugField()

    panels = [
        MultiFieldPanel([
            FieldPanel("title"),
            FieldPanel("slug"),
        ], heading="Menu"),
        InlinePanel("menu_items", label="Menu Item")
    ]

    def __str__(self):
        return self.title
zerolab commented 2 years ago

Can you try version 1.2.1?

enzedonline commented 2 years ago

@DBonbon - It'll be the link_page field in the orderable as per issue #573 fixed by v 1.2.1

You can also use

    override_translatable_fields = [
        SynchronizedField("link_page", overridable=False),
    ]    

to make the link_page non-translatable (you'd reference it by something like link_page.localized in your code to get the translated page).

zerolab commented 2 years ago

Will close based on @enzedonline's confirmation

DBonbon commented 2 years ago

Thanks for getting back. Enzo's suggestion worked for me! (I actually read his 'clusterable post' before, though as he suggested it might be resolved shortly, I didn't apply it). If that is of interest for you.. any new migrations forced me to reset the DB and the virtualenv (I did try --Fake and deleted pyc). As upon clicking the menu snippet admin showed an error:"column cms_menu.translation_key does not exist" in the file.../.virtualenvs/bup/lib/python3.9/site-packages/django/db/backends/utils.py, line 89, in _execute