I have these models:
class Project():
name = models.CharField(max_length=512)
class Task():
name = models.CharField(max_length=256)
project = models.ForeignKey('prosystem.Project',
related_name='tasks',
on_delete=models.CASCADE)
class TaskFile(models.Model):
task = models.ForeignKey(Task, on_delete=models.CASCADE, related_name='tasks')
file = models.FileField(upload_to=self.make_file_path()) # I want this to be dynamic path
def make_file_path(self):
# pseudocode, does not work
pid = self.task.project.id
tid = self.task.id
path = f'project_{pid}/task_{tid}/'
return path
I want to upload files to a folder based on its Task
id and its parent Project
id. How can I do that?