Search code examples
pythondjangosqlitefile-managementfilefield

Django multiple files in one field


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.


Solution

  • 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/')