6
file = models.FileField(upload_to=settings.FILE_PATH)

For uploading a file in django models I used the above line. But For uploading multiple file through django admin model what should I do? I found this But this is for forms. Can I use this for models?

1 Answer 1

5

If you want to have multiple files for the same field you would have to write your own field and widget based on the form field you have found otherwise have a separate model for file with a foreign key to your main model and use ModelInline.

models.py

class Page(models.Model):
    title = models.CharField(max_length=255)

class PageFile(models.Model):
    file = models.ImageField(upload_to=settings.FILE_PATH)
    page = models.ForeignKey('Page')

admin.py

 class PageFileInline(admin.TabularInline):
        model = PageFile

 class PageAdmin(admin.ModelAdmin):
        inlines = [PageFileInline,]
Sign up to request clarification or add additional context in comments.

3 Comments

Field 'file' doesn't have a default value. This is the error I am getting.
file = models.ImageField(upload_to=settings.FILE_PATH, blank=True, null=True) or post complete traceback
i added the traceback in question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.