Hi dears. I would like to upload multiple images on one field in Django admin panel. Clients don’t need to upload files. Files will be uploaded only by moderators in admin panel. I tried to override the widget as it shown in documentation but it didn’t work. Please help me. Thanks in advance.
Django doesn’t support multiple files in a single field.
About the closest you could come would be to create a table for the images with a Foreign Key to whatever page you want those images related to, and then use an InlineModelAdmin to add those images.
Thanks for your answer. But Django has multiple files in a single field (File Uploads | Django documentation | Django) version. I need just override default model. I override the model, but Django didn’t get multiple files in back-end, can’t solve this problem and decided to write here about this problem.
I tried that version - one to many version. But i don’t want to implement that method.
That’s form field, not model field. When using it, then those individual files need to be processed and managed individually.
We’re talking about the admin here - not a generalized solution. If it’s critical to do this as a multiple file upload, then create your own form with its own view and handle it directly.
From the docs at: The Django admin site | Django documentation | Django
The admin’s recommended use is limited to an organization’s internal management tool. It’s not intended for building your entire front end around.
If you need to provide a more process-centric interface that abstracts away the implementation details of database tables and fields, then it’s probably time to write your own views.
It’s a common mistake for people to rely solely upon the admin interface for creating their input forms. It’s easy to reach the point where it’s less work to produce your own views than it is to try and make the admin do everything desired.
Thanks for your answer. I will try it, to implement.
Dear, can you help me. I tried to solve my above problem with the choosing multiple images in one field, but could not save the request.FILES to database. I tried to handle this issue in ModelAdmin. I can choose some images in admin panel in one field overriding the image field with setting multiple: True, but after saving the chosen images did not saved, saved only last image from that chosen list of images.
Correct. Django does not support multiple files in a single model ImageField.
If it’s so important that you use the
multiple: True option in the file upload form widget, then create your own view to process it. But you’re still going to need multiple FileFields in the database to store them. A FileField in a model stores a reference to one file.
Thanks for your answer!