2012-02-21 156 views
0

我聽說可能不會爲此創建,但我真的希望只需要文件名就可以獲得slug和title。Django prepopulated_fields在添加'cfakepath'時將字段添加到目標ImageField

class RandomAdmin(admin.ModelAdmin): 
    prepopulated_fields = { 
     'slug': ('image',), 
     'title': ('image',) 
    } 

其中 '形象' 是一個ImageField的...

image = models.ImageField(upload_to="random_uploads") 

如果文件名是 'abc_123.jpg',我得到 'cfakepathabc_123jpg'。我想要'abc_123jpg'或'abc_123'。

我的任何提示? :)

回答

2

無法修改prepopulated_fields_js.html,因爲它只是查找相關字段的值,所以不能輕易完成。

換句話說,你不能通過改變ModelAdmin中的某些東西來做到這一點。您必須覆蓋prepopulated_fields_js.html並製作一些特定的例外。

+0

謝謝!我會暫時離開..也許我會稍後再探討。 – teewuane 2012-02-22 21:09:36