Django multi file upload fields
List item
registration start date
Year
Vin#
Make
Title Owner (Upload field) ==== (can be several files)
HUT # (Upload field) ==== (can be several files)
Ifta # (Upload field) ==== (can be several files)
I need that model
If file upload fields had to be for a single file, then it would be okay, but how Can I handle that model?
(Should I create ForeignKey models for every file_upload field in order to handle multi file uploads??)
I would write something like this:
files_titleowner = models.ManyToManyField(FileTitleOwner, related_name="mymodel_filetitleowner", blank=True)
...
and so on. I usually specify the related_name attribute for each many to many field.
FileTitleOwner could be like this:
class FileTitleOwner(models.Model):
file = models.FileField(upload_to=user_directory_path,
null=True, blank=True,
verbose_name="...")
...
Also, user_directory_path is a function which returns the pathname for the file to be stored on file system:
def user_directory_path(instance, filename):
...
return f"{<construct opportunely a directory name>}/{filename}"