简体   繁体   English

在Django中,我如何以管理形式而不是完整的站点域显示站点缩写?

[英]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解决方案有几点要注意:

  1. 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,并在将其包含在页面中时对其进行正确编码

  2. You'll have to override the template for that admin page to be able to include the custom JS 您必须覆盖该管理页面的模板才能包含自定义JS

  3. It won't work for people who have JS disabled 它不适用于禁用JS的人

  4. 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.

相关问题 我如何使网站无响应? - How would I make a site non responsive? 如何安全地从另一个站点将表单发布到Django站点 - How to post a form to django site, securely and from another site 在Django管理网站上实现一个简单的jquery函数 - implementing a simple jquery function to the django admin site 网站主题; 我将如何使这段代码摘录起作用? - Site themes; how would I make this extract of code work? 我将如何动态克隆站点并将自定义 css 应用于它? - How would I dynamically clone a site and apply custom css to it? 如何对网站进行编码,以便缓存远程站点中的jscript,而不是不断对其进行重新加载 - How to code website so jscript from remote site is cached, rather than being constantly reloaded 编辑此代码以在屏幕尺寸而非设备上重定向到移动网站 - Editing this code to redirect to mobile site on screen size rather than device 如何使jQuery Mobile网站上的完整网站按钮正常工作? - How do I get the full site button on jQuery Mobile site to work correctly? IISNode网站列出文件夹而不是启动server.js - IISNode site lists folder rather than starting server.js 如何在 SHarePoint 2013 站点中的表单中显示计算的列值 - How to display a calculated column value in a form in SHarePoint 2013 site
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM