onespacemedia / cms

A collection of Django extensions that add content-management facilities to Django projects.
BSD 3-Clause "New" or "Revised" License
14 stars 7 forks source link

Unpublishing certain pages from list view throws a KeyError #196

Open Kane1994 opened 4 years ago

Kane1994 commented 4 years ago

This bug only seems to happen when attempting to turn a page offline via the page list view. It works fine when turning the page offline in the page detail view.

This happens when unpublishing a Plain Content page, which has the following model:

class PlainContent(ProjectContentBase):

kicker = models.CharField(
    max_length=50,
    blank=True,
    null=True,
)

content_title = models.CharField(
    max_length=140,
    blank=True,
    null=True,
)

content = HtmlField(
    blank=True,
    null=True,
)

sidebar_blocks = JetSortedManyToManyField(
    'site.SidebarBlock',
    blank=True,
)

def __str__(self):
    return self.page.title`

It throws KeyError: 'sidebar_blocks' on this specific code:

for field in content_obj._meta.many_to_many: getattr(content_obj, field.name).set(form.cleaned_data[field.name])

Which can be found online 345 on cms/apps/pages/admin.py