Skip to content

Instantly share code, notes, and snippets.

@timonweb
Created May 6, 2012 15:33
Show Gist options
  • Save timonweb/2622961 to your computer and use it in GitHub Desktop.
Save timonweb/2622961 to your computer and use it in GitHub Desktop.
Django FileField with upload_to determined at runtime
def content_file_name(instance, filename):
return '/'.join(['content', instance.user.username, filename])
class Content(models.Model):
name = models.CharField(max_length=200)
user = models.ForeignKey(User)
file = models.FileField(upload_to=content_file_name)
@timonweb
Copy link
Author

timonweb commented May 6, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment