Wagtail admin ,CheckboxSelectMultiple not saving data

血红的双手。 提交于 2019-12-13 16:05:58

问题


@register_snippet
class Numbers(models.Model):
    number = models.IntegerField()

class State(models.Model):
    state = models.CharField(max_length=100)
    number = ParentalManyToManyField(Numbers)


class HomeStateNumber(State):
    page = ParentalKey('home.HomePage', related_name='helpline')
    api_fields = ['state', 'number']

    panels = [
        FieldPanel('state'),
        FieldPanel('number',widget=forms.CheckboxSelectMultiple),
    ]

class HomePage(Page):

content_panels = [
    FieldPanel('title'),
    ImageChooserPanel('cover_page'),
    InlinePanel('ticker', label="ticker"),
    InlinePanel('helpline', label="helpline"),
]

I want to add one than more number in a state , wagtail shows correct order in admin , when you select number from multiple and save the page, data is not saved. It remains None (queryset) Is there any other way to do this ? I think i am doing wrong somewhere Please help


回答1:


Models using ParentalManyToManyField need to inherit from modelcluster.models.ClusterableModel.

from modelcluster.models import ClusterableModel

class State(ClusterableModel):
    state = models.CharField(max_length=100)
    number = ParentalManyToManyField(Numbers)

Also, make sure you have django-modelcluster version 4.0 (or above) installed - older versions had a bug preventing m2m relations in inline objects from working.



来源:https://stackoverflow.com/questions/47858703/wagtail-admin-checkboxselectmultiple-not-saving-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!