django-whatever icon indicating copy to clipboard operation
django-whatever copied to clipboard

Callable file upload_to

Open sneawo opened this issue 13 years ago • 1 comments

I have in model

def upload_userfile_path(instance, filename):
    return 'files/%s/%s' % (instance.user.id, filename)
class UserFile(models.Model):
    user = models.ForeignKey(User)
    file = models.FileField(upload_to=upload_userfile_path)

in test

user = any_model(User, is_active=True)
any_model(UserFile, user=user)

And error as result:

AttributeError: 'NoneType' object has no attribute 'user'
at generated_filepath = field.upload_to(None, xunit.any_string(ascii_letters, 10, 20))

sneawo avatar Jan 27 '12 05:01 sneawo

Callable upload_to doesn't work with instance argument yet. I don't have time to fix it myself right now, but I'd love to merge if anyone is willing to fix it.

coagulant avatar Jan 29 '12 18:01 coagulant