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 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…