[英]In Django, how would I display a site abbreviation in an admin form rather than the full site domain?
So we are using Django's sites
contrib app, and a particular page in the admin is going to be pretty packed, so we're saving space any way we can. 因此,我们正在使用Django的
sites
contrib应用程序,并且管理员中的特定页面将非常紧凑,因此我们将尽我们所能节省空间。 Our site profiles each have an abbreviation associated with it, which would tighten things up a lot, so we want to use those instead of the full names in the admin form. 我们的网站配置文件都有一个与之相关的缩写,这会使事情更加严格,因此我们希望使用这些名称代替管理员表单中的全名。 Not sure what the best way of doing this is.
不确定执行此操作的最佳方法是什么。
I saw this post , and it looked like it might be along the lines of what I'm after, but I really don't want to have to create an entirely new form. 我看到了这篇文章 ,看起来可能跟我追求的差不多,但是我真的不想创建一个全新的表单。 Seems like overkill just to make a single field display differently.
仅仅为了使一个字段的显示方式不同而已,似乎有些过分了。 Any ideas on what the best way to do this is?
关于最佳方法的任何想法是什么? Presently, I'm thinking about a javascript solution -- send over a map with the abbreviations keyed to the site ids and do some replacing, but that seems a little hacky.
目前,我正在考虑使用javascript解决方案-在地图上发送带有缩写的缩写(键入网站ID)并进行一些替换,但这似乎有点不客气。
The point of forms is to control how fields are displayed. 表单的重点是控制字段的显示方式。 It shouldn't be much effort to make a new form with the correct choice names.
使用正确的选择名称创建新表格应该不花很多功夫。
A Javascript solution has a couple of points to be aware of: Javascript解决方案有几点要注意:
You need to build & maintain the list of names and abbreviations as JSON, and correctly encode it when you include it in the page 您需要将名称和缩写列表构建并维护为JSON,并在将其包含在页面中时对其进行正确编码
You'll have to override the template for that admin page to be able to include the custom JS 您必须覆盖该管理页面的模板才能包含自定义JS
It won't work for people who have JS disabled 它不适用于禁用JS的人
The page will "jump" as the browser will first render the page with the values from the form, before you JS changes them and the browser re-renders the page. 该页面将“跳转”,因为在您更改JS并重新渲染该页面之前,浏览器将首先使用表单中的值呈现该页面。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.