I have given my code below. It is having a image field. I'm using django forms and custom templates to fill and store this information. And I want to allow users to upload 0 to 10 images for each book as per their wish. So how can I achieve it. My requirements are as follows:
- Minimum - 0 file, Maximum - 10 files
- Allowed file types - *.jpg, *.jpeg, *.gif, *.png
- Either it can be a browse file field or a button which will call a window to select multiple files.
- I want to save and retrieve these images and edit them in future.
models.py
class Book(models.Model):
title = models.CharField(max_length = 200)
author = models.CharField(max_length = 200)
cost = models.IntegerField()
description = models.TextField()
image = models.ImageField(upload_to = 'images/books/', null = True, blank = True)
forms.py
class BookForm(forms.ModelForm):
class Meta:
model = Book
widgets = {
'location' : forms.TextInput(attrs={'placeholder': 'Location'}),
'title' : forms.TextInput(attrs={'placeholder': 'Title'}),
'author' : forms.TextInput(attrs={'placeholder': 'Author'}),
'cost' : forms.TextInput(attrs={'placeholder': 'Price'}),
'description': forms.Textarea(attrs={'placeholder': 'Description'}),
}
Before asking this question, I tried Garmoncheg django_multiuploader and Scompt multifile widget. But none of them helped me. I'm working on this task for the past two days, but couldn't get it working. So Please suggest me a way of completing this task successfully.