2014-01-09 45 views
1

django admin.ModelAdmin自動填充字段標題中的prepopulated_fields當我在django管理界面中輸入名稱時。如何使用Django中的prepopulated_fields W/O音譯?

prepopulated_fields = { 
    'title': ('name',), 
} 

如何在沒有音譯的情況下製作相同的功能。

例:

name: Говядо 
title: govyado 

旺旺:

name: Говядо 
title: Говядо 

回答

0

admin.py

class Media: 
    js = ('/static/js/jquery.min.js', 
      '/static/js/slug.js') 

slug.js

window.onload = function() { 
    document.getElementById("id_name").onkeyup = function() { 
     var e = document.getElementById("id_title"); 
     if (!e._changed) { e.value = document.getElementById("id_name").value; } 
    } 
}