Django 模型中的函数无法识别

Django 模型中的函数无法识别,django,django-models,Django,Django Models,我尝试扩展已有的模型,所以在其中添加了“缩略图”。不幸的是,与此相关的函数无法识别,django console为我提供了: thumbnail = models.ImageField(upload_to=_get_upload_image, blank=True, null=True) NameError: name '_get_upload_image' is not defined 有人能帮我解决这个问题吗 Django 1.6.5 models.py(短版) 我通过将函数放在类的顶部解

我尝试扩展已有的模型,所以在其中添加了“缩略图”。不幸的是,与此相关的函数无法识别,django console为我提供了:

thumbnail = models.ImageField(upload_to=_get_upload_image, blank=True, null=True)
NameError: name '_get_upload_image' is not defined
有人能帮我解决这个问题吗

Django 1.6.5 models.py(短版)


我通过将函数放在类的顶部解决了这个问题

class Feed(models.Model):

    def _get_upload_image(instance, filename):
        return "images/%s_%S" % (str(time()).replace('.','_'), filename)

    link = models.CharField(blank=True, max_length=450)
    url = models.CharField(blank=True, max_length=450)
    title = models.CharField(blank=True, null=True, max_length=250)
    category = models.ForeignKey(Category, blank=True, null=True)
    user = models.ForeignKey(User, blank=True, null=True)
    last_update = models.DateField(blank=True, null=True, editable=False)
    country = models.ForeignKey(Country, blank=True, null=True)
    thumbnail = models.ImageField(upload_to=_get_upload_image, blank=True, null=True)

\u get\u upload\u image
的访问权限从一个类方法更改为一个助手方法(缩进一级),它将工作。我在这个类中已经有了更多的函数,这是app django feedme,我想扩展它。
class Feed(models.Model):

    def _get_upload_image(instance, filename):
        return "images/%s_%S" % (str(time()).replace('.','_'), filename)

    link = models.CharField(blank=True, max_length=450)
    url = models.CharField(blank=True, max_length=450)
    title = models.CharField(blank=True, null=True, max_length=250)
    category = models.ForeignKey(Category, blank=True, null=True)
    user = models.ForeignKey(User, blank=True, null=True)
    last_update = models.DateField(blank=True, null=True, editable=False)
    country = models.ForeignKey(Country, blank=True, null=True)
    thumbnail = models.ImageField(upload_to=_get_upload_image, blank=True, null=True)