当前位置: 首页>>代码示例>>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;未经允许,请勿转载。