Search code examples
wagtailwagtail-snippet

file field doesn't gets saved with wagtail inline field


I'm trying to user inline panels but for plain Django model in wagtail like it's described here. I got it working with a plain char field.

When I try to use a models.FileField I get an error message after the save action. "No file chosen". It seem it doesn't saves the file

Here is the code I used:

from django.db import models
from modelcluster.models import ClusterableModel
from wagtail.wagtailadmin.edit_handlers import FieldPanel, InlinePanel
from wagtail.wagtailsnippets.models import register_snippet
from modelcluster.fields import ParentalKey


class Slide(models.Model):
    file = models.FileField('PDF / Image',null=True, upload_to="slides")
    mymodel = ParentalKey('mymodel.mymodel', related_name='slides',
                            on_delete=models.CASCADE, null=True)


@register_snippet
class MyModel(ClusterableModel):
    name = models.CharField(max_length=255)
    number = models.IntegerField()

    panels = [
        FieldPanel('name'),
        FieldPanel('number'),
        InlinePanel('slides', label="slides"),
    ]

    def __str__(self):
        return self.name

How to get the files saved? Should it be possible?


Solution

  • This is a known bug that will be fixed in the next release of Wagtail (due in a couple of weeks): https://github.com/wagtail/wagtail/issues/2251