使用引导程序呈现的 Django FilteredSelectMultiple 小部件 [英] Django FilteredSelectMultiple widget rendered with bootstrap

查看:25
本文介绍了使用引导程序呈现的 Django FilteredSelectMultiple 小部件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试复制 django 应用程序管理员中使用的 FilteredSelectMultiple 小部件.但是我的小部件呈现出非常不同的

使用 呈现这个小部件.

我正在使用 django-crispy-forms,其他小部件使用除了 FilteredSelectMultiple 小部件

之外的引导程序

任何建议

提前致谢

解决方案

django-admin-bootstrapped 指定样式来覆盖 django 管理员默认值,即像文件 overrides.css.小部件 FilteredSelectMultiple 使用 css 类 .selector 并且您的页面应应用声明的 css 选择器 从overrides.css的第39行到第119行,所以你会需要通过更改表单中的 Media 类将其样式添加到您的页面:

类媒体:css = {'all':('/admin/css/widgets.css', 'admin/css/overrides.css'),}js = ('/admin/jquery.js','/admin/jsi18n/')

或直接包含它的模板:

<link href="{{ STATIC_URL }}admin/css/overrides.css" type="text/css" rel="stylesheet"/>

希望这能解决您的问题

I am trying to replicate the FilteredSelectMultiple widget used in the admin of the django apps. But my widget is rendered very different

The widget in the admin using django-suit or django_admin_bootstrapped is rendered with bootstrap:

I define my widget and media the forms.py:

class ProcFTPForm(forms.ModelForm):
      id_archivo = forms.ModelMultipleChoiceField(queryset=Archivo_Descarga.objects.all(),required=True,widget=FilteredSelectMultiple("Archivo",is_stacked=False))
      class Media:
       css = {'all':('/admin/css/widgets.css',),}
       js = ('/admin/jquery.js','/admin/jsi18n/')

      def __init__(self, *args, **kwargs):
          super(ProcFTPForm, self).__init__(*args, **kwargs)
          self.helper = FormHelper()

      class Meta:
            model = Lista_Archivos

And in the template I call the media files in this way:

{{ form.media }}

How can I render the FilteredSelectMultiple widget looking similar like the widget from the admin. In other words how can I render this widget using bootstrap.

I am using django-crispy-forms and the other widgets are rendered with bootstrap except the FilteredSelectMultiple widget

Any advice

Thanks in advance

解决方案

django-admin-bootstrapped specifies styles to override django admin defaults i.e. like the file overrides.css. The widget FilteredSelectMultiple use the css class .selector and your page should apply css selectors declared from line 39 to 119 of overrides.css, so you will need to add its styles to your page, either by changing your Media class in form:

class Media:
   css = {'all':('/admin/css/widgets.css', 'admin/css/overrides.css'),}
   js = ('/admin/jquery.js','/admin/jsi18n/')

or directly include it template:

<link href="{{ STATIC_URL }}admin/css/overrides.css" type="text/css" rel="stylesheet" />

Hope this solve your problem

这篇关于使用引导程序呈现的 Django FilteredSelectMultiple 小部件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆