I have *File* model for uploading file.

class File(models.Model):
    files = models.FileField(upload_to='sampleorder/%y/%m/%d', null=True, 
blank=True)
    order_detail = models.ForeignKey(OrderDetail, on_delete=models.SET_NULL, 
null=True)

and for multiple file upload i have *form.py*

class FileForm(forms.ModelForm):
    class Meta:
        model = File
        fields = ['files']
        widgets = {
            'files': forms.ClearableFileInput(attrs={'multiple': True}),
        }

and in *admin.py*

@admin.register(File)class FileAdmin(admin.ModelAdmin):
    form = FileForm
    list_display = ['id']

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

             instance.save()

return super(FileAdmin, self).save_model(request, obj, form, change)

but its only save latest file. how to save multiple file at time? i also 
see this Upload multiple files using Files Field in Django Admin 
<https://stackoverflow.com/questions/49734064/upload-multiple-files-using-files-field-in-django-admin>
 question 
but can configure where i am wrong.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/389bb47f-4bea-450f-854c-350a050d9344%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to