Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wagtail admin ,CheckboxSelectMultiple not saving data

@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

like image 303
sourabhah Avatar asked Feb 12 '26 12:02

sourabhah


1 Answers

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.

like image 106
gasman Avatar answered Feb 14 '26 01:02

gasman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!