3

I want to create multiple submenus for different pages of a website. So, I created a snippet called "Submenus".

The submenu contains an object called submenu_items. On the webpage, that translates to the top level of navigation. Then, each submenu_item has a dropdown_items. That way, under each top level link, I can create a dropdown with more links.

Problem:
Whenever I create a new submenu_item, it creates 3 dropdown_items (example in photo below). I expected for it to provide the ADD DROPDOWN ITEM button. Then, I would create one at a time as necessary. The code seems to generate three by default.

I tried deleting them, saving the snippet. But when I click on the snippet, they are there again. I tried recreating the entire model and re-migrating everything. I still get the same problem.

Can someone point out what I may be doing wrong? Is there some rule for nested elements I'm missing?

enter image description here

@register_snippet
class Submenu(ClusterableModel):
    text = models.CharField(max_length=255)
    subsite_url = models.CharField(max_length=255)

    panels = [
        FieldPanel('text'),
        FieldPanel('subsite_url'),
        InlinePanel('submenu_items', label="Submenu Items"),
    ]

    def __str__(self):
        return self.text

class SubmenuItem(ClusterableModel, Orderable):
    page = ParentalKey(Submenu, on_delete=models.CASCADE, related_name='submenu_items')

    menu_item = models.CharField(blank=True, max_length=250)
    internal_url = models.CharField(blank=True, max_length=250)

    panels = [
        FieldPanel('menu_item'),
        FieldPanel('internal_url'),
        InlinePanel('dropdown_items', label="Dropdown Items"),
    ]    

class DropdownItem(Orderable):
    page = ParentalKey(SubmenuItem, on_delete=models.CASCADE, related_name='dropdown_items')

    menu_item = models.CharField(blank=True, max_length=250)
    internal_url = models.CharField(blank=True, max_length=250)

    panels = [
        FieldPanel('menu_item'),
        FieldPanel('internal_url'),
    ]
JustBlossom
  • 1,259
  • 3
  • 24
  • 53

1 Answers1

0

What's the purpose of the DropdownItem Class? I believe SubmenuItem and DropdownItem are redundant. If you go back to the wagtail tutorial and look at the gallery images example, you'll find your answer.

http://docs.wagtail.io/en/v2.0/getting_started/tutorial.html#images

The authors create BlogPageGalleryImage which is inherits Orderable. You could use the same ParentalKey structure for SubmenuItem.

wgarlock
  • 96
  • 6
  • 1
    I am trying to create a menu with dropdown items. So the top menu has items which are Orderable (like in the image tutorial). Then, each one of those items can have items that go in their dropdown. Those items are also Orderable. So, I need an Orderable in an Orderable which seems to work but with a strange side effect. – JustBlossom May 28 '19 at 12:05