Django-在管理员外部使用多对多水平界面 [英] Django - using Many-to-Many horizontal interface outside of admin

查看:93
本文介绍了Django-在管理员外部使用多对多水平界面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个m2m字段的表单.我希望该字段看起来像django管理站点的水平界面...¿我该怎么做?

I'm working in a form with a m2m field. I want that this field looks like the horizontal interface of the django admin site... ¿how i can do it?

谢谢...

推荐答案

您需要使用FilteredSelectMultiple小部件

from django.contrib.admin.widgets import FilteredSelectMultiple
from django import forms
from .models import Person


class PersonForm(forms.ModelForm):
    some_field = forms.ModelMultipleChoiceField(Person.objects.all(), widget=FilteredSelectMultiple("Person", False, attrs={'rows':'2'}))
    class Meta:
        model = Person   

您还需要包括管理员使用的Javascript和CSS.这是一个示例

You will also need to include the Javascript and CSS used in the admin. Here's an example

这篇关于Django-在管理员外部使用多对多水平界面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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