我想將自定義的upload_to函數傳遞給我的模型imageField,但我想將該函數定義爲模型函數....是可能的嗎?Django ImageField將可調用函數傳遞給upload_to
class MyModel(models.Model):
...
image = models.ImageField(upload_to=self.get_image_path)
...
def get_image_path(self, filename):
...
return image_path
現在我知道我不能用「自我」引用它,因爲自己並沒有在這一點上存在......是有辦法做到這一點?如果沒有 - 定義該功能的最佳位置在哪裏?
的可能重複的[Django的的FileField與upload_to在運行時確定(http://stackoverflow.com/questions/1190697/django-filefield-with-upload-to-determined-at-runtime) – 2012-02-01 08:10:30
呀,看看Paulo提到的鏈接 - 它在那裏清楚地顯示了它(沒有'self.',在models.py中將可調用的函數定義爲函數) – 2012-02-01 11:49:15
看起來像我的答案畢竟在這裏: http:// stackoverflow.com/questions/1190697/django-filefield-with-upload-to-determined-at-runtime – jduncan 2012-05-30 03:29:09