當前位置: 首頁>>代碼示例>>Python>>正文


Python autocomplete.ModelSelect2方法代碼示例

本文整理匯總了Python中dal.autocomplete.ModelSelect2方法的典型用法代碼示例。如果您正苦於以下問題:Python autocomplete.ModelSelect2方法的具體用法?Python autocomplete.ModelSelect2怎麽用?Python autocomplete.ModelSelect2使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在dal.autocomplete的用法示例。


在下文中一共展示了autocomplete.ModelSelect2方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: from dal import autocomplete [as 別名]
# 或者: from dal.autocomplete import ModelSelect2 [as 別名]
def __init__(self, request, params, model, model_admin):
        if self.parameter_name:
            raise AttributeError(
                'Rename attribute `parameter_name` to '
                '`field_name` for {}'.format(self.__class__)
            )
        self.parameter_name = '{}__{}__exact'.format(self.field_name, self.field_pk)
        super(AutocompleteFilter, self).__init__(request, params, model, model_admin)

        self._add_media(model_admin)

        field = forms.ModelChoiceField(
            queryset=self.get_queryset_for_field(model, self.field_name),
            widget=autocomplete.ModelSelect2(
                url=self.get_autocomplete_url(request),
            )
        )

        attrs = self.widget_attrs.copy()
        attrs['id'] = 'id-%s-dal-filter' % self.field_name
        if self.is_placeholder_title:
            attrs['data-placeholder'] = self.title
        self.rendered_widget = field.widget.render(
            name=self.parameter_name,
            value=self.used_parameters.get(self.parameter_name, ''),
            attrs=attrs
        ) 
開發者ID:shamanu4,項目名稱:dal_admin_filters,代碼行數:29,代碼來源:__init__.py

示例2: __init__

# 需要導入模塊: from dal import autocomplete [as 別名]
# 或者: from dal.autocomplete import ModelSelect2 [as 別名]
def __init__(self, **kwargs):
        super().__init__(**kwargs)

        # Set front-end widgets

        # Unset fields (remove these filters from URL-params)
        del self.filters['file_number']
        del self.filters['ecli']
        del self.filters['slug']

        # Hidden widgets
        for field_name in ['court__slug']:
            self.filters.get(field_name).field.widget = HiddenInput()

        # Extra widgets
        self.filters.get('court').field.widget = autocomplete.ModelSelect2(
                url='courts:autocomplete',
                attrs={
                    'data-placeholder': _('Court'),
                }
            )

        self.filters.get('court__state').field.widget = autocomplete.ModelSelect2(
                url='courts:state_autocomplete',
                attrs={
                    'data-placeholder': _('State'),
                },
            )
        # self.filters.get('has_reference_to_law').field.widget = VisibleIfSetInput(model=Law, model_related='book') 
開發者ID:openlegaldata,項目名稱:oldp,代碼行數:31,代碼來源:filters.py


注:本文中的dal.autocomplete.ModelSelect2方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。