In Django admin, you can add several files at once by using the Django Multiuploader app. To use this app, follow the steps below:
pip install django-multiuploader
INSTALLED_APPS = [
# other apps
'multiuploader',
]
python manage.py makemigrations
python manage.py migrate
from django.db import models
from multiuploader.models import MultiuploaderImage
class MyFile(models.Model):
description = models.CharField(max_length=100)
files = models.ManyToManyField(MultiuploaderImage, blank=True)
def __str__(self):
return self.description
from django import forms
from multiuploader.forms import MultiuploaderFileForm
from .models import MyFile
class MultiImageForm(forms.ModelForm):
class Meta:
model = MyFile
fields = '__all__'
widgets = {
'files': MultiuploaderFileForm()
}
from django.contrib import admin
from .models import MyFile
from .forms import MultiImageForm
class MyFileAdmin(admin.ModelAdmin):
form = MultiImageForm
admin.site.register(MyFile, MyFileAdmin)
With the above configuration, you can now upload multiple files at once in Django admin.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2021-12-19 11:00:00 +0000
Seen: 7 times
Last updated: Mar 04 '22
How can I set up Gunicorn with a Django Project?
Looking for a Python Module that finds Tags for a Text describing its Content
Need a Function in Python to remove entries less than 2 digits from an Array
How can I convert a Document in Python?
How can I program a Loop in Python?
How can I enable Python Code Highlighting in Askbot?