coagulant/django-whatever — Issue #24: Callable file upload_to
Author: sneawo
Created: 2012-01-27 05:35:14+00:00
State: open

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))