Last active
December 20, 2015 12:19
-
-
Save tomchristie/6130319 to your computer and use it in GitHub Desktop.
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 get_upload_to(instance, filename): | |
user = instance.user | |
return 'uploads/%s/%s' % (user.username, filename) | |
class MyModel(models.Model): | |
upload = models.FileField(upload_to=get_upload_to) | |
... |
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 upload(request): | |
obj = MyModel() | |
obj.user = request.user | |
obj.upload = request.FILES['upload'] | |
obj.save() | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You gave me this on #django but I ran into a snag I don't even understand.
May you please help with https://gist.github.com/urbanslug/6143884 I get the error: << 'User' object has no attribute 'rfind' >>
Traceback at: http://pastebin.com/VmA2zLEk