Hello! There is a model with FileField and ImageField fields, and a field
user = models.ForeignKey(User)
It is necessary that the upload_to is formed from the user id (and preferably still from an arbitrary string, but this is not necessary).
For example:
1) option:
"321 / userfile.png"
"321 / doc1.txt"
Option 2:
"321 / avatars / userfile.png"
"321 / documents / doc1.txt"
I tried to transfer to the upload_to function:
def make_upload_path(self, filename): return str(self.user.id)
But this only works if I define this function before all the fields, and I cannot define different paths for different fields (as in the second example).
How can this behavior be implemented?