2014-01-09 44 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; } 
    } 
}