Forums

Need to upload multiple files on FileField in DJango Admin

So I have a model with a FileField, I just need to know how to upload more files on the same FileField. I don't want to create other model or other FileField. This is my code :

file = models.FileField(blank=True, upload_to='documents')

def file_link(self):
    if self.file:
        return "<a href='%s'>download</a>" % (self.file.url,)
    else:
        return "No attachment"

file_link.allow_tags = True

[edit by admin: best guess at formatting]

I think that's probably a question best asked at Stack Overflow. That said, all of the solutions I found to similar-sounding problems there involved creating new models for files; in general, if you want multiple "things" -- files, in this case -- then you need either a model with a foreign key back to the thing that owns the files, or you need separate fields in your model. Django doesn't really have a concept of fields that contain lists of things.

You were right. Thanks.