0

I created a reusable abstract model (mixin) which includes required fields (without blank=True). Then added to a page model inline model which inherits that mixin. Finally I cannot save a page despite I filled in all the required fields. My app crashes with a message those fields cannot be blank. When I eliminate required option everything works well. The same thing if I use this model obviously (as pure inline model, not a mixin) with required fields. What's wrong here? If my approach is quite complicated, what is a better way to reuse code in this case?

Mixin:

class ContentSectionOneMixin(models.Model):
    class Meta:
        abstract = True

    content_section_one_title = models.TextField(_('Title'), null=True)
    content_section_one_body = RichTextField(_('Lead'), null=True)
    content_section_button_caption = RichTextField(
        _('Caption'),
        null=True,
        blank=True
    )

    content_panels = [
        MultiFieldPanel(
            heading=_('Content Section One'),
            children=[
                FieldPanel('content_section_one_title'),
                FieldPanel('content_section_one_body'),
                FieldPanel('content_section_button_caption'),
        ],
        classname='collapsible collapsed'
        ),
    ]

Inline model

class HomePageContentFlow(Orderable, ContentSectionOneMixin):
    page = ParentalKey('HomePage', related_name='content_flow')

    panels = ContentSectionOneMixin.content_panels
miric
  • 53
  • 10
  • Hey, could you please indicate what version of Python, Django and Wagtail you are using - I am unable to replicate the issue you are facing. The full error stack trace would also be helpful. – LB Ben Johnston Dec 15 '17 at 05:22
  • One note though - for an improvement - is to be be sure you actually want to set null=True. Django [docs advise](https://docs.djangoproject.com/en/2.0/ref/models/fields/) `Avoid using null on string-based fields such as CharField and TextField.` Also the way RichTextFields work is they will always save something, even just an empty

    tag so null=True is not needed. Here is more info about null/blank on models: https://stackoverflow.com/questions/8609192/differentiate-null-true-blank-true-in-django
    – LB Ben Johnston Dec 15 '17 at 05:24
  • Python 3.6.3, Django 1.11.7, Wagtail 1.13.1. Thanks for indexing the idea around Null. I will check the docs. – miric Dec 15 '17 at 08:56

0 Answers0