Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding AbstactMainMenuItem with choice fields fails on second saving #334

Closed
sowinski opened this issue Jul 3, 2019 · 2 comments
Closed

Comments

@sowinski
Copy link

sowinski commented Jul 3, 2019

Hi,

I tried to extend the MainMenu item but unfortunately hitting save is only working the first time. The second time it is failing.
Here is My code:

class CustomMainMenuItem(AbstractMainMenuItem):

    DISPLAY_ALWAYS         = 0
    DISPLAY_ONLY_LOGGEDIN  = 1
    DISPLAY_ONLY_LOGGEDOUT = 2

    DISPLAY_CHOICES = (
        (DISPLAY_ALWAYS, _('Show always')),
        (DISPLAY_ONLY_LOGGEDIN, _('Show only logged in')),
        (DISPLAY_ONLY_LOGGEDOUT, _('Show only logged out')),
    )

    NORMAL      = 0
    HIGHLIGHTED = 1

    ITEM_TYPE_CHOICES = (
        (NORMAL, _('Normal')),
        (HIGHLIGHTED, _('Highlighted')),
    )

    menu = ParentalKey(
        'wagtailmenus.MainMenu',
        on_delete=models.CASCADE,
        related_name="custom_menu_items", # important for step 3!
    )

    display_type    = models.PositiveSmallIntegerField(default=DISPLAY_ALWAYS, choices=DISPLAY_CHOICES)
    item_type       = models.PositiveSmallIntegerField(default=NORMAL, choices=ITEM_TYPE_CHOICES)

    hover_description = models.CharField(
        max_length=250,
        blank=True
    )

    # Also override the panels attribute, so that the new fields appear
    # in the admin interface
    panels = (
        PageChooserPanel('link_page'),
        FieldPanel('link_url'),
        FieldPanel('url_append'),
        FieldPanel('link_text'),
        FieldPanel('display_type'),
        FieldPanel('item_type'),
        FieldPanel('allow_subnav'),
    )

How to reproduce it:

  1. Add the to your code. (run makemigrations and migrate)
  2. Create new Main MenuItem => Works
  3. Add another Main Menu Item or change the old one without hitting the choices field and click on Save => Boom
@sowinski
Copy link
Author

sowinski commented Jul 3, 2019

It is only not working while using 'condensedinlinepanel'

I guess there is a problem with choice fields. Is this a bug within condensedinlinepanel or wagtailmenus?

@ababic
Copy link
Collaborator

ababic commented Jul 3, 2019

Hi @sowinski. This does look like a bug in condensedinlinepanel. The following existing issue looks very similar:
wagtail-deprecated/wagtail-condensedinlinepanel#57

@ababic ababic closed this as completed Sep 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants