[Answered ]-How in Django upload Photo based on Gallery name from other model field?

2👍

upload_to needs to a callable and specified as part of your model field.

def photo_upload_to(instance, filename):
    return '{media}/photohouse/{gallery}/{filename}'.format(
        media=settings.MEDIA_ROOT, 
        gallery=instance.PhotoGallery.name,
        filename=filename)

class Photo(models.Model):
    ....
    File = models.FileField(upload_to=photo_upload_to)

Leave a comment