I am trying to add an option to add multiple files at once in a form, and I found the solution with using ClearableFileInput:
class Image(models.Model):
id = models.AutoField(primary_key=True)
post = models.ForeignKey(BlogEntry, on_delete=models.CASCADE)
photo = models.ImageField(null=True, blank=True, upload_to='media/')
photo_objects = models.Manager()
class ImageForm(forms.ModelForm):
class Meta:
model = Image
fields = ['photo', ]
widgets = {
'photo': forms.ClearableFileInput(attrs={'multiple': True})
}
However, when I tried to run it using runserver, it gave me an error. Can somebody help me with fixing it? Is there another straightforward option to add multiple files?
I tried to search difference solutions on the internet but some of them did not work while others looked too complicated for my current level. I also see this option to upload multiple files in the official documentation (https://docs.djangoproject.com/en/dev/topics/http/file-uploads/) but I wonder if there is a simpler version in which I would not need to create MultipleFileInput and MultipleFileField by myself. Is there something in Django to enable multiple file upload?