django为“ListField”生成自定义小部件,并显示列表

时间:2021-02-12 19:41:31

Using django-ldapdb, I'm trying to manage user ssh keys stored in our ldap directory. The main problem I have is that when a ListField is displayed on a ModelForm, it renders an input with a repr'd list as a unicode string when the actual datatype returned by ListField.to_python() is a list.

使用django-ldapdb,我尝试管理存储在ldap目录中的用户ssh密钥。我遇到的主要问题是,当一个ListField显示在一个ModelForm上时,当ListField.to_python()返回的实际数据类型是一个列表时,它将一个带有repr'd列表的输入呈现为一个unicode字符串。

What is the best way to write a custom widget that would turn that list into a set of input boxes or any custom html? The end goal is something which looks very similar to this so that a user could easily add new ssh keys or remove existing ones. The existing stuff like in that screenshot of mango will only display the ssh key fingerprint and "comment" or email instead of the raw key.

编写自定义小部件的最佳方式是什么?最终目标与此非常相似,用户可以轻松添加新的ssh密钥或删除现有密钥。在芒果屏幕截图中,现有的内容只会显示ssh密钥指纹和“评论”或电子邮件,而不是原始密钥。

Bonus points to anyone who can figure out a way to hook up some jQuery and make it similar to the django admin inline pretty (google django jquery admin and click the djangoadvent article. I don't have enough SO points to link it).

额外的好处是,任何人都可以找到一种方法来连接一些jQuery并使其类似于django管理内联美观(谷歌django jQuery admin并单击djangoadvent文章)。我没有足够的点数来链接它。

How would you implement something like this?

如何实现这样的东西?

1 个解决方案

#1


1  

Here's a similar question with a recipe for ListField widget that could get you started:
Django-nonrel form field for ListField

这里有一个关于ListField小部件的配方的类似问题,它可以让您开始:ListField的Django-nonrel表单字段

#1


1  

Here's a similar question with a recipe for ListField widget that could get you started:
Django-nonrel form field for ListField

这里有一个关于ListField小部件的配方的类似问题,它可以让您开始:ListField的Django-nonrel表单字段