Created
May 6, 2012 15:33
-
-
Save timonweb/2622961 to your computer and use it in GitHub Desktop.
Django FileField with upload_to determined at runtime
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
taken from here: http://stackoverflow.com/questions/1190697/django-filefield-with-upload-to-determined-at-runtime