﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
19876	Using a staticmethod for a FileField's upload_to attribute doesn't work	Baptiste Mispelon	nobody	"When trying to use a `staticmethod` for a `FileField`'s `upload_to` attribute, the results are not what you'd expect.

{{{#!python
# models.py

class Foo(models.Model):
    @staticmethod
    def my_callable(instance, filename):
        return 'foo'
    
    f = models.FileField(upload_to=my_callable)
}}}

The following code shows what happens:

{{{#!python
from myapp.models import Foo

instance = Foo()
print instance._meta.get_field('f').generate_filename(instance, 'bar')
}}}

I would expect the output of this to be `'foo'` but instead, it prints `u'<staticmethod object at 0x1c8b130>/bar'`.


Putting a breakpoint inside `FileField.__init__`, it appears that at the time the field is initialized, `upload_to` is a staticmethod object which is not itself callable (it has a `__func__` attribute which is the callable we are looking for)."	Bug	closed	Database layer (models, ORM)	1.5-rc-1	Normal	wontfix	filefield upload_to staticmethod		Unreviewed	0	0	0	0	0	0
