Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
83 views
in Technique[技术] by (71.8m points)

python - Django File upload in model

Considering that we`ve got the model below:

class Project(models.Model):
    file1 = models.FileField(upload_to='projects/', blank =True)
    file2 = models.FileField(upload_to='projects/', blank =True)
    file3 = models.FileField(upload_to='projects/', blank =True)
    file4 = models.FileField(upload_to='projects/', blank =True)
    file5 = models.FileField(upload_to='projects/', blank =True)

How many file1 can we create? If I want to create severals files, I usually write my code this way:

class File1(models.Model):
    project = models.ForeignKey(Project, on_delete=models.CASCADE)
    file = models.FileField(upload_to='projects/', blank =True)

Instead to create severals models File1, File2, File 3, Is there a way to upload several file1 in Django using only the model Project? I mean to not have to create a model for each file1, file2, file3 if we need to upload several of them.

Many Thanks,

question from:https://stackoverflow.com/questions/65837350/django-file-upload-in-model

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...