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


Python ChoiceField.__init__方法代碼示例

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


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

示例1: __init__

# 需要導入模塊: from django.forms.fields import ChoiceField [as 別名]
# 或者: from django.forms.fields.ChoiceField import __init__ [as 別名]
def __init__(self, queryset, empty_label="---------", cache_choices=None,
                 required=True, widget=None, label=None, initial=None,
                 help_text='', to_field_name=None, limit_choices_to=None,
                 *args, **kwargs):
        if required and (initial is not None):
            self.empty_label = None
        else:
            self.empty_label = empty_label
        if cache_choices is not None:
            warnings.warn("cache_choices has been deprecated and will be "
                "removed in Django 1.9.",
                RemovedInDjango19Warning, stacklevel=2)
        else:
            cache_choices = False
        self.cache_choices = cache_choices

        # Call Field instead of ChoiceField __init__() because we don't need
        # ChoiceField.__init__().
        Field.__init__(self, required, widget, label, initial, help_text,
                       *args, **kwargs)
        self.queryset = queryset
        self.limit_choices_to = limit_choices_to   # limit the queryset later.
        self.choice_cache = None
        self.to_field_name = to_field_name 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:26,代碼來源:models.py

示例2: __init__

# 需要導入模塊: from django.forms.fields import ChoiceField [as 別名]
# 或者: from django.forms.fields.ChoiceField import __init__ [as 別名]
def __init__(self, data=None, files=None, instance=None,
                 save_as_new=False, prefix=None, queryset=None, **kwargs):
        if instance is None:
            self.instance = self.fk.remote_field.model()
        else:
            self.instance = instance
        self.save_as_new = save_as_new
        if queryset is None:
            queryset = self.model._default_manager
        if self.instance.pk is not None:
            qs = queryset.filter(**{self.fk.name: self.instance})
        else:
            qs = queryset.none()
        self.unique_fields = {self.fk.name}
        super().__init__(data, files, prefix=prefix, queryset=qs, **kwargs)

        # Add the generated field to form._meta.fields if it's defined to make
        # sure validation isn't skipped on that field.
        if self.form._meta.fields and self.fk.name not in self.form._meta.fields:
            if isinstance(self.form._meta.fields, tuple):
                self.form._meta.fields = list(self.form._meta.fields)
            self.form._meta.fields.append(self.fk.name) 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:24,代碼來源:models.py

示例3: __init__

# 需要導入模塊: from django.forms.fields import ChoiceField [as 別名]
# 或者: from django.forms.fields.ChoiceField import __init__ [as 別名]
def __init__(self, data=None, files=None, instance=None,
                 save_as_new=False, prefix=None, queryset=None, **kwargs):
        if instance is None:
            self.instance = self.fk.remote_field.model()
        else:
            self.instance = instance
        self.save_as_new = save_as_new
        if queryset is None:
            queryset = self.model._default_manager
        if self.instance.pk is not None:
            qs = queryset.filter(**{self.fk.name: self.instance})
        else:
            qs = queryset.none()
        self.unique_fields = {self.fk.name}
        super(BaseInlineFormSet, self).__init__(data, files, prefix=prefix,
                                                queryset=qs, **kwargs)

        # Add the generated field to form._meta.fields if it's defined to make
        # sure validation isn't skipped on that field.
        if self.form._meta.fields and self.fk.name not in self.form._meta.fields:
            if isinstance(self.form._meta.fields, tuple):
                self.form._meta.fields = list(self.form._meta.fields)
            self.form._meta.fields.append(self.fk.name) 
開發者ID:Yeah-Kun,項目名稱:python,代碼行數:25,代碼來源:models.py

示例4: __init__

# 需要導入模塊: from django.forms.fields import ChoiceField [as 別名]
# 或者: from django.forms.fields.ChoiceField import __init__ [as 別名]
def __init__(self, data=None, files=None, auto_id='id_%s', prefix=None,
                 initial=None, error_class=ErrorList, label_suffix=':',
                 empty_permitted=False, instance=None):
        opts = self._meta
        if instance is None:
            if opts.model is None:
                raise ValueError('ModelForm has no model class specified.')
            # if we didn't get an instance, instantiate a new one
            self.instance = opts.model()
            object_data = {}
        else:
            self.instance = instance
            object_data = model_to_dict(instance, opts.fields, opts.exclude)
        # if initial was provided, it should override the values from instance
        if initial is not None:
            object_data.update(initial)
        # self._validate_unique will be set to True by BaseModelForm.clean().
        # It is False by default so overriding self.clean() and failing to call
        # super will stop validate_unique from being called.
        self._validate_unique = False
        super(BaseModelForm, self).__init__(data, files, auto_id, prefix, object_data,
                                            error_class, label_suffix, empty_permitted) 
開發者ID:blackye,項目名稱:luscan-devel,代碼行數:24,代碼來源:models.py

示例5: __init__

# 需要導入模塊: from django.forms.fields import ChoiceField [as 別名]
# 或者: from django.forms.fields.ChoiceField import __init__ [as 別名]
def __init__(self, queryset, empty_label="---------",
                 required=True, widget=None, label=None, initial=None,
                 help_text='', to_field_name=None, limit_choices_to=None,
                 *args, **kwargs):
        if required and (initial is not None):
            self.empty_label = None
        else:
            self.empty_label = empty_label

        # Call Field instead of ChoiceField __init__() because we don't need
        # ChoiceField.__init__().
        Field.__init__(self, required, widget, label, initial, help_text,
                       *args, **kwargs)
        self.queryset = queryset
        self.limit_choices_to = limit_choices_to   # limit the queryset later.
        self.to_field_name = to_field_name 
開發者ID:drexly,項目名稱:openhgsenti,代碼行數:18,代碼來源:models.py


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