Django multiple files in one field

1.6k views Asked by At

I am trying to make a database using sqlite3 with a field for multiple files so that i can have a file list on mt model info page. For example if the model is student and he needs to store an unspecified number of homework files and needs to be able to add, view, edit and delete them. Any help is much appreciated.

1

There are 1 answers

1
Astik Anand On BEST ANSWER

You can make a homeworkfile model. In that model add a file_upload field.

And then relate student table to homeworkfile model using one-to-many relationship.

class homeworkfile(models.Model):
    student = models.ForeignKey(Student, on_delete=models.CASCADE)
    file_upload = models.FileField(upload_to='uploads/%Y/%m/%d/')