1

Here i have class models:

models.py

class Parameter(models.Model):
    files = models.FileField(
        upload_to='uploaded',
        blank=True,
        null=True,
    )

and i have this in my admin.py

class ParameterAdmin(admin.ModelAdmin):
    form = Parameter

and i add it in my forms.py so it can select more then one file

class ParameterForm(forms.ModelForm):
    def __init__(self, *args, **kwargs):
        super(ParameterForm, self).__init__(*args, **kwargs)
        self.fields['files '] = forms.FileField(
            widget=forms.ClearableFileInput(attrs={'multiple': True}),
        )

But, after i try to choose and select multiple files via django admin.. Not all files are uploaded and it only upload one latest selected file..

How can i upload multiple files via django admin..? I don't need views.py and html from.. i just need django admin can upload multiple files.. Simple

2 Answers 2

1

You should override save_model function of ParameterAdmin like this:

def save_model(self, request, obj, form, change):
    files = request.FILES.getlist('files')
    for f in files:
        instance = Parameter(files=f)
        instance.save()

It will save all files.

Sign up to request clarification or add additional context in comments.

Comments

-1

A FileField only stores a single file. If you want multiple files, you need either multiple fields (but unless each of those files as a distinct specific role it's a bad design) or a distinct ParameterFile model with a foreign key on Parameter and a FileField, and then use an InlineModelAdmin.

1 Comment

Nope! He need to push 1 button, and choose 100 files to upload! He don't want to push "Upload button" 100 times! So.. it's not about inline.... it's about multiple file upload

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.