The answer[1] to that stack overflow question looks correct to me. To 
summarize, the "files" field on your model only stores a single file. Instead 
of files field, you'll need to create a new model that's foreign keyed back to 
your File model to store an arbitrary number of multiple files.

[1] https://stackoverflow.com/a/49734180

On December 18, 2018 1:49:44 PM CST, Muhammad Dilshad Khaliq 
<[email protected]> wrote:
>
>
>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.

-- 
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/1F7F9B83-F4A8-4C6D-AC46-EB7C00A748ED%40fattuba.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to