Search code examples
djangowagtailwagtail-admin

Suddenly We're not able to add more images in specific page in Wagtail with 400 Bad Request Error


This is the Gallery Page models, we've added 142 image so far, and we're able to add more images in other pages, but on this one, even if I delete an image and try to add another one I got an 400 Bad Request on publishing and Error while sending preview data. on previewing

class Gallery(Page):
    
    content_panels = Page.content_panels + [
        InlinePanel('media', label=_('Gallery Media'))
    ]


class GalleryMedia(ClusterableModel, Orderable):
    category = ParentalManyToManyField("gallery.GalleryCategory", blank=True)
    gallery = ParentalKey(
        "gallery.Gallery", on_delete=models.CASCADE, related_name="media", null=True
    )
    image = models.ForeignKey(
        "wagtailimages.Image", on_delete=models.CASCADE, related_name="+", null=True, blank=True, 
        help_text="The recommended sizes and dimensions for the images are:  350*200 / Aspect Ratio 7 : 4 - 350*700 / Aspect Ratio 1 : 2 - 350*500 / Aspect Ratio 7 : 10"
    )
    video_url = models.URLField(blank=True)
    video = models.ForeignKey(
        "wagtailvideos.Video",
        related_name="+",
        null=True,
        blank=True,
        on_delete=models.SET_NULL,
    )
    show_large = models.BooleanField(default=False)
    show_on_homepage = models.BooleanField(default=False, verbose_name="Show on HomePage")

    panels = [
        ImageChooserPanel("image"),
        FieldPanel("video_url"),
        VideoChooserPanel("video"),
        FieldPanel("show_large"),
        FieldPanel("show_on_homepage"),
        MultiFieldPanel([FieldPanel("category", widget=CheckboxSelectMultiple),]),
    ]


class GalleryCategory(models.Model):
    name = models.CharField(max_length=50)

    panels = [
        FieldPanel("name"),
    ]

Solution

  • It is possible you are hitting the https://docs.djangoproject.com/en/3.2/ref/settings/#data-upload-max-number-fields. Tweaking that and related settings should work