当前位置: 首页>>代码示例>>Python>>正文


Python widgets.FilteredSelectMultiple方法代码示例

本文整理汇总了Python中django.contrib.admin.widgets.FilteredSelectMultiple方法的典型用法代码示例。如果您正苦于以下问题:Python widgets.FilteredSelectMultiple方法的具体用法?Python widgets.FilteredSelectMultiple怎么用?Python widgets.FilteredSelectMultiple使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.contrib.admin.widgets的用法示例。


在下文中一共展示了widgets.FilteredSelectMultiple方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: formfield_for_manytomany

# 需要导入模块: from django.contrib.admin import widgets [as 别名]
# 或者: from django.contrib.admin.widgets import FilteredSelectMultiple [as 别名]
def formfield_for_manytomany(self, db_field, request=None, **kwargs):
        """
        Get a form Field for a ManyToManyField.
        """
        # If it uses an intermediary model that isn't auto created, don't show
        # a field in admin.
        if not db_field.rel.through._meta.auto_created:
            return None
        db = kwargs.get('using')

        if db_field.name in self.raw_id_fields:
            kwargs['widget'] = widgets.ManyToManyRawIdWidget(db_field.rel,
                                    self.admin_site, using=db)
            kwargs['help_text'] = ''
        elif db_field.name in (list(self.filter_vertical) + list(self.filter_horizontal)):
            kwargs['widget'] = widgets.FilteredSelectMultiple(
                db_field.verbose_name,
                db_field.name in self.filter_vertical
            )

        if 'queryset' not in kwargs:
            queryset = self.get_field_queryset(db, db_field, request)
            if queryset is not None:
                kwargs['queryset'] = queryset

        form_field = db_field.formfield(**kwargs)
        if isinstance(form_field.widget, SelectMultiple) and not isinstance(form_field.widget, CheckboxSelectMultiple):
            msg = _('Hold down "Control", or "Command" on a Mac, to select more than one.')
            help_text = form_field.help_text
            form_field.help_text = string_concat(help_text, ' ', msg) if help_text else msg
        return form_field 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:33,代码来源:options.py

示例2: formfield_for_manytomany

# 需要导入模块: from django.contrib.admin import widgets [as 别名]
# 或者: from django.contrib.admin.widgets import FilteredSelectMultiple [as 别名]
def formfield_for_manytomany(self, db_field, request, **kwargs):
        """
        Get a form Field for a ManyToManyField.
        """
        # If it uses an intermediary model that isn't auto created, don't show
        # a field in admin.
        if not db_field.remote_field.through._meta.auto_created:
            return None
        db = kwargs.get('using')

        autocomplete_fields = self.get_autocomplete_fields(request)
        if db_field.name in autocomplete_fields:
            kwargs['widget'] = AutocompleteSelectMultiple(db_field.remote_field, self.admin_site, using=db)
        elif db_field.name in self.raw_id_fields:
            kwargs['widget'] = widgets.ManyToManyRawIdWidget(db_field.remote_field, self.admin_site, using=db)
        elif db_field.name in list(self.filter_vertical) + list(self.filter_horizontal):
            kwargs['widget'] = widgets.FilteredSelectMultiple(
                db_field.verbose_name,
                db_field.name in self.filter_vertical
            )

        if 'queryset' not in kwargs:
            queryset = self.get_field_queryset(db, db_field, request)
            if queryset is not None:
                kwargs['queryset'] = queryset

        form_field = db_field.formfield(**kwargs)
        if (isinstance(form_field.widget, SelectMultiple) and
                not isinstance(form_field.widget, (CheckboxSelectMultiple, AutocompleteSelectMultiple))):
            msg = _('Hold down "Control", or "Command" on a Mac, to select more than one.')
            help_text = form_field.help_text
            form_field.help_text = format_lazy('{} {}', help_text, msg) if help_text else msg
        return form_field 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:35,代码来源:options.py

示例3: formfield_for_manytomany

# 需要导入模块: from django.contrib.admin import widgets [as 别名]
# 或者: from django.contrib.admin.widgets import FilteredSelectMultiple [as 别名]
def formfield_for_manytomany(self, db_field, request, **kwargs):
        """
        Get a form Field for a ManyToManyField.
        """
        # If it uses an intermediary model that isn't auto created, don't show
        # a field in admin.
        if not db_field.remote_field.through._meta.auto_created:
            return None
        db = kwargs.get('using')

        if db_field.name in self.raw_id_fields:
            kwargs['widget'] = widgets.ManyToManyRawIdWidget(db_field.remote_field, self.admin_site, using=db)
        elif db_field.name in (list(self.filter_vertical) + list(self.filter_horizontal)):
            kwargs['widget'] = widgets.FilteredSelectMultiple(
                db_field.verbose_name,
                db_field.name in self.filter_vertical
            )

        if 'queryset' not in kwargs:
            queryset = self.get_field_queryset(db, db_field, request)
            if queryset is not None:
                kwargs['queryset'] = queryset

        form_field = db_field.formfield(**kwargs)
        if isinstance(form_field.widget, SelectMultiple) and not isinstance(form_field.widget, CheckboxSelectMultiple):
            msg = _('Hold down "Control", or "Command" on a Mac, to select more than one.')
            help_text = form_field.help_text
            form_field.help_text = format_lazy('{} {}', help_text, msg) if help_text else msg
        return form_field 
开发者ID:Yeah-Kun,项目名称:python,代码行数:31,代码来源:options.py

示例4: formfield_for_manytomany

# 需要导入模块: from django.contrib.admin import widgets [as 别名]
# 或者: from django.contrib.admin.widgets import FilteredSelectMultiple [as 别名]
def formfield_for_manytomany(self, db_field, request=None, **kwargs):
        """
        Get a form Field for a ManyToManyField.
        """
        # If it uses an intermediary model that isn't auto created, don't show
        # a field in admin.
        if not db_field.remote_field.through._meta.auto_created:
            return None
        db = kwargs.get('using')

        if db_field.name in self.raw_id_fields:
            kwargs['widget'] = widgets.ManyToManyRawIdWidget(db_field.remote_field,
                                    self.admin_site, using=db)
            kwargs['help_text'] = ''
        elif db_field.name in (list(self.filter_vertical) + list(self.filter_horizontal)):
            kwargs['widget'] = widgets.FilteredSelectMultiple(
                db_field.verbose_name,
                db_field.name in self.filter_vertical
            )

        if 'queryset' not in kwargs:
            queryset = self.get_field_queryset(db, db_field, request)
            if queryset is not None:
                kwargs['queryset'] = queryset

        form_field = db_field.formfield(**kwargs)
        if isinstance(form_field.widget, SelectMultiple) and not isinstance(form_field.widget, CheckboxSelectMultiple):
            msg = _('Hold down "Control", or "Command" on a Mac, to select more than one.')
            help_text = form_field.help_text
            form_field.help_text = string_concat(help_text, ' ', msg) if help_text else msg
        return form_field 
开发者ID:drexly,项目名称:openhgsenti,代码行数:33,代码来源:options.py

示例5: test_filtered_many_to_many

# 需要导入模块: from django.contrib.admin import widgets [as 别名]
# 或者: from django.contrib.admin.widgets import FilteredSelectMultiple [as 别名]
def test_filtered_many_to_many(self):
        self.assertFormfield(Band, 'members', widgets.FilteredSelectMultiple,
                             filter_vertical=['members']) 
开发者ID:nesdis,项目名称:djongo,代码行数:5,代码来源:tests.py

示例6: test_m2m_widgets

# 需要导入模块: from django.contrib.admin import widgets [as 别名]
# 或者: from django.contrib.admin.widgets import FilteredSelectMultiple [as 别名]
def test_m2m_widgets(self):
        """m2m fields help text as it applies to admin app (#9321)."""
        class AdvisorAdmin(admin.ModelAdmin):
            filter_vertical = ['companies']

        self.assertFormfield(Advisor, 'companies', widgets.FilteredSelectMultiple,
                             filter_vertical=['companies'])
        ma = AdvisorAdmin(Advisor, admin.site)
        f = ma.formfield_for_dbfield(Advisor._meta.get_field('companies'), request=None)
        self.assertEqual(
            f.help_text,
            'Hold down "Control", or "Command" on a Mac, to select more than one.'
        ) 
开发者ID:nesdis,项目名称:djongo,代码行数:15,代码来源:tests.py

示例7: test_render

# 需要导入模块: from django.contrib.admin import widgets [as 别名]
# 或者: from django.contrib.admin.widgets import FilteredSelectMultiple [as 别名]
def test_render(self):
        # Backslash in verbose_name to ensure it is JavaScript escaped.
        w = widgets.FilteredSelectMultiple('test\\', False)
        self.assertHTMLEqual(
            w.render('test', 'test'),
            '<select multiple name="test" class="selectfilter" '
            'data-field-name="test\\" data-is-stacked="0">\n</select>'
        ) 
开发者ID:nesdis,项目名称:djongo,代码行数:10,代码来源:tests.py

示例8: test_stacked_render

# 需要导入模块: from django.contrib.admin import widgets [as 别名]
# 或者: from django.contrib.admin.widgets import FilteredSelectMultiple [as 别名]
def test_stacked_render(self):
        # Backslash in verbose_name to ensure it is JavaScript escaped.
        w = widgets.FilteredSelectMultiple('test\\', True)
        self.assertHTMLEqual(
            w.render('test', 'test'),
            '<select multiple name="test" class="selectfilterstacked" '
            'data-field-name="test\\" data-is-stacked="1">\n</select>'
        ) 
开发者ID:nesdis,项目名称:djongo,代码行数:10,代码来源:tests.py

示例9: make_gop_app_access_form

# 需要导入模块: from django.contrib.admin import widgets [as 别名]
# 或者: from django.contrib.admin.widgets import FilteredSelectMultiple [as 别名]
def make_gop_app_access_form():
    """
    Create the group form dynamically, adding fields for permissions and groups for each app.
    """
    all_apps = TethysApp.objects.all()

    properties = {}

    for app_qs in all_apps:
        all_permissions_queryset = Permission.objects \
            .filter(codename__icontains=app_qs.package) \
            .exclude(codename__icontains=':access_app')

        properties[f'{app_qs.package}_permissions'] = forms.ModelMultipleChoiceField(
            queryset=all_permissions_queryset,
            required=False,
            widget=FilteredSelectMultiple(
                verbose_name=f'{app_qs.name} Permissions',
                is_stacked=False
            )
        )

        group_with_app_perms = []
        for g in GroupObjectPermission.objects.filter(object_pk=app_qs.pk).values('group_id').distinct():
            group_with_app_perms.append(int(g['group_id']))
        all_groups_queryset = Group.objects.filter(pk__in=group_with_app_perms)

        properties[f'{app_qs.package}_groups'] = forms.ModelMultipleChoiceField(
            queryset=all_groups_queryset,
            required=False,
            widget=FilteredSelectMultiple(
                verbose_name=f'{app_qs.name} Groups',
                is_stacked=False
            )
        )

    GOPAppAccessFormDynamic = type(
        'GOPAppAccessFormDynamic',
        (GOPAppAccessForm,),
        properties
    )

    return GOPAppAccessFormDynamic 
开发者ID:tethysplatform,项目名称:tethys,代码行数:45,代码来源:admin.py


注:本文中的django.contrib.admin.widgets.FilteredSelectMultiple方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。