how can i set a model’s field using the existance of a foreignkey as a condition?

You are on correct path. upload_to can point to a function.

def user_directory_path(instance: Person, filename): 
    # file will be uploaded to MEDIA_ROOT / your path 
    if  # 
        return f"team_{}/user_{}"
        return f"person_{}"

# ...
class Person(models.Model): 
    files = models.FileField(upload_to = user_directory_path) 

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top