 <p>The <code>upload_to</code> argument can be a function, <a href="https://docs.djangoproject.com/en/1.9/ref/models/fields/#django.db.models.FileField.upload_to" rel="nofollow">as described in the documentation</a>:</p> <pre><code>def group_based_upload_to(instance, filename): return "image/group/{}/{}".format(instance.group.id, filename) class Group_Photo(models.Model): group = models.ForeignKey(Group) photo = models.ImageField(upload_to=group_based_upload_to) </code></pre> <p>The function takes two arguments - instance of the model to which the file is being attached and the original name of the file. It has to return a relative path under witch the file will be saved. It will be appended to the path defined in the <code>MEDIA_ROOT</code> setting.</p> <p>The example above uses directories based on group's numeric id. You can obviously use other fields, for example to use the slug (if it has one) just replace <code>instance.group.id</code> with <code>instance.group.slug</code>.</p>