Python Developer
Python Developer

Reputation: 1

How should I store files inside Django

I am writing an application in Django Rest Framework that accepts employee data and generates a barcode for him in pdf format. then I have to give these files on request. question: how should i store the files created in the application? I have a model of the employee itself and I have a second model with a one-to-one relationship with the employee model and a field for the file. what type of field to use: FileField or FilePathField? the generated files will be stored on the server. they will have to be given through the API in the form of binary data

Upvotes: 0

Views: 447

Answers (1)

Romain
Romain

Reputation: 334

It depends :) You can store file directly into the database, or in the filesystem.

In db, you could use a BinaryField, but, most of the time, its a bad choice.

In the filesystem, you effectively have this two choices :

  • FilePathField is only a specialized CharField to handle path
  • however FileField handle all painful aspects of file manipulation. You just give a file pointer, and django do the rest :)

If you don't like to reinvent the wheel, you should definitively use a FileField.

Upvotes: 1

Related Questions