如何在 django postman 中使用 django ajax-selects 更改 DropDown 显示

发布于 2024-12-22 03:18:56 字数 306 浏览 6 评论 0原文

我目前正在使用名为 django-postman 的应用程序,该应用程序利用 django-ajax-selects 在内部发送消息时提供用户名自动完成功能。 django-ajax-selects 中显示的视图相当简洁,但当我实际使用它时,下拉列表的视图相当粗糙。

我已附上屏幕截图。任何人都可以帮助我了解为什么我会得到这个基本的粗略观点。 在此处输入图像描述

从这里可以看出,建议的名称出现在最后。我还想知道是否可以添加用户头像及其姓名,以使其更具视觉吸引力。

I am currently using an application named django-postman that makes use of django-ajax-selects to provide autocomplete feature in user names when sending messages internally. The view shown in django-ajax-selects is quite neat, but when I actually used it, the view of the dropdown was prety crude.

I have attached a screenshot. Can anybody please help in knowing why am I getting this basic crude view.
enter image description here

As can be seen here the suggested name is coming right at the end. I also wanted to know if I can add the user gravatar, along with their name to make it more visually appealing.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蓝颜夕 2024-12-29 03:18:56

我最终想出了如何解决这个问题,但没有更新这个答案。但既然我收到了评论,我想我应该分享我所知道的一切。我不完全记得我写了什么以便它开始正常工作,但我将分享我在文件中所做的所有设置,并希望它也适用于其他人

首先我安装了 django-ajax-selects自动完成字段。这是应用程序的链接 https://github.com/crucialfelix/django-ajax-selects< /a>

在项目中安装后,您需要在设置文件中进行这些特定设置

POSTMAN_AUTOCOMPLETER_APP = {    {% if is_autocompleted %}
 <script type="text/javascript" src="{{ STATIC_URL }}js/jquery.autocomplete.min.js"></script>
<link href="{{ STATIC_URL }}css/jquery.autocomplete.css" type="text/css" media="all" rel="stylesheet" />
 {% endif %}
        'name': 'ajax_select',
        'field': 'AutoCompleteField',
        'arg_name': 'channel',
        'arg_default': 'user', # no default, mandatory to enable the feature
}

AJAX_SELECT_BOOTSTRAP = True
AJAX_SELECT_INLINES = 'inline'

AJAX_LOOKUP_CHANNELS = {
       # pass a dict with the model and the field to search against
       'user'  : {'model':'auth.user', 'search_field':'username'},
}

您需要在模板中包含 jquery 自动完成文件。现在该库已与 jquery ui 集成,因此请确保使用旧的 jquery 自动完成 js 文件。这可能是它不起作用的原因之一。

{% if is_autocompleted %}
 <script type="text/javascript" src="{{ STATIC_URL }}js/jquery.autocomplete.min.js"></script>
<link href="{{ STATIC_URL }}css/jquery.autocomplete.css" type="text/css" media="all" rel="stylesheet" />
 {% endif %}

正如我所说,我不太记得我做了什么,以至于应用程序开始工作,但这些是我的项目中存在的所有设置。

谢谢

I eventually figured out how to solve this problem, but did not update this answer. But since I have received comments, I think I should share whatever I know. I don't exactly remember what did I do write so that it started working correctly, but I will share all the settings that I have made in my files, and hope it works for others as well

Firstly I installed django-ajax-selects for the autocomplete field. here is the link for the app https://github.com/crucialfelix/django-ajax-selects

After having installed in project you need these specific settings in the settings file

POSTMAN_AUTOCOMPLETER_APP = {    {% if is_autocompleted %}
 <script type="text/javascript" src="{{ STATIC_URL }}js/jquery.autocomplete.min.js"></script>
<link href="{{ STATIC_URL }}css/jquery.autocomplete.css" type="text/css" media="all" rel="stylesheet" />
 {% endif %}
        'name': 'ajax_select',
        'field': 'AutoCompleteField',
        'arg_name': 'channel',
        'arg_default': 'user', # no default, mandatory to enable the feature
}

AJAX_SELECT_BOOTSTRAP = True
AJAX_SELECT_INLINES = 'inline'

AJAX_LOOKUP_CHANNELS = {
       # pass a dict with the model and the field to search against
       'user'  : {'model':'auth.user', 'search_field':'username'},
}

You need to include the jquery autocomplete file in your template. Now this library has been integrated with jquery ui so make sure that you use the old jquery autocomplete js file. This could potentially be one of the reasons for it not working.

{% if is_autocompleted %}
 <script type="text/javascript" src="{{ STATIC_URL }}js/jquery.autocomplete.min.js"></script>
<link href="{{ STATIC_URL }}css/jquery.autocomplete.css" type="text/css" media="all" rel="stylesheet" />
 {% endif %}

As I said, I don't exactly remember what I did, such that the app started working but these are all the settings that exist in my project.

Thanks

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文