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


Python fields.BLANK_CHOICE_DASH属性代码示例

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


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

示例1: __init__

# 需要导入模块: from django.db.models import fields [as 别名]
# 或者: from django.db.models.fields import BLANK_CHOICE_DASH [as 别名]
def __init__(self, *args, **kwargs):
        request = kwargs.pop('request', None)
        super(FilterUserForm, self).__init__(*args, **kwargs)
        for field in self.fields.keys():
            self.fields[field].widget.attrs['placeholder'] = self.fields[field].label
        self.fields['best_girl'].choices = getGirls(with_japanese_name=(request and request.LANGUAGE_CODE == 'ja'))
        self.fields['language'].choices = BLANK_CHOICE_DASH + self.fields['language'].choices
        self.fields['os'].choices = BLANK_CHOICE_DASH + self.fields['os'].choices
        self.fields['verified'].choices = BLANK_CHOICE_DASH + [(3, _('Only'))] + self.fields['verified'].choices
        del(self.fields['verified'].choices[-1])
        self.fields['verified'].initial = None
        self.fields['os'].initial = None
        self.fields['language'].initial = None
        del(self.fields['status'].choices[0])
        del(self.fields['status'].choices[0])
        self.fields['status'].choices = BLANK_CHOICE_DASH + [('only', _('Only'))] + self.fields['status'].choices
        #self.fields['status'].choices.insert(1, ('only', _('Only'))) this doesn't work i don't know why 
开发者ID:MagiCircles,项目名称:SchoolIdolAPI,代码行数:19,代码来源:forms.py

示例2: render_option

# 需要导入模块: from django.db.models import fields [as 别名]
# 或者: from django.db.models.fields import BLANK_CHOICE_DASH [as 别名]
def render_option(self, name, selected_choices,
                      option_value, option_label):
        option_value = force_text(option_value)
        if option_label == BLANK_CHOICE_DASH[0][1]:
            option_label = _("All")
        data = self.data.copy()
        data[name] = option_value
        selected = data == self.data or option_value in selected_choices
        try:
            url = data.urlencode()
        except AttributeError:
            url = urlencode(data)
        return self.option_string() % {
            'attrs': selected and ' class="selected"' or '',
            'query_string': url,
            'label': force_text(option_label)
        } 
开发者ID:BeanWei,项目名称:Dailyfresh-B2C,代码行数:19,代码来源:widgets.py

示例3: __init__

# 需要导入模块: from django.db.models import fields [as 别名]
# 或者: from django.db.models.fields import BLANK_CHOICE_DASH [as 别名]
def __init__(self, *args, **kwargs):
        queryset = kwargs.pop('queryset', None)
        self.many = kwargs.pop('many', self.many)
        if self.many:
            self.widget = self.many_widget
            self.form_field_class = self.many_form_field_class

        kwargs['read_only'] = kwargs.pop('read_only', self.read_only)
        super(RelatedField, self).__init__(*args, **kwargs)

        if not self.required:
            # Accessed in ModelChoiceIterator django/forms/models.py:1034
            # If set adds empty choice.
            self.empty_label = BLANK_CHOICE_DASH[0][1]

        self.queryset = queryset 
开发者ID:erigones,项目名称:esdc-ce,代码行数:18,代码来源:relations.py

示例4: choices_to_field

# 需要导入模块: from django.db.models import fields [as 别名]
# 或者: from django.db.models.fields import BLANK_CHOICE_DASH [as 别名]
def choices_to_field(cls):
        _choices = [BLANK_CHOICE_DASH[0], ]
        for rel in cls._meta.related_objects:
            object_name = rel.related_model._meta.object_name.capitalize()
            field_name = rel.remote_field.name.capitalize()
            name = "{}-{}".format(object_name, field_name)
            remote_model_name = rel.related_model._meta.verbose_name
            verbose_name = "{}-{}".format(
                remote_model_name, rel.remote_field.verbose_name
            )
            _choices.append((name, verbose_name))
        return sorted(_choices) 
开发者ID:Wenvki,项目名称:django-idcops,代码行数:14,代码来源:models.py

示例5: get_action_choices

# 需要导入模块: from django.db.models import fields [as 别名]
# 或者: from django.db.models.fields import BLANK_CHOICE_DASH [as 别名]
def get_action_choices(self, request, default_choices=BLANK_CHOICE_DASH):
        """
        Return a list of choices for use in a form object.  Each choice is a
        tuple (name, description).
        """
        choices = [] + default_choices
        for func, name, description in six.itervalues(self.get_actions(request)):
            choice = (name, description % model_format_dict(self.opts))
            choices.append(choice)
        return choices 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:12,代码来源:options.py

示例6: test_default_choices

# 需要导入模块: from django.db.models import fields [as 别名]
# 或者: from django.db.models.fields import BLANK_CHOICE_DASH [as 别名]
def test_default_choices(self):
        field = EnumField(TestEnum)
        choices = field.get_choices(blank_choice=BLANK_CHOICE_DASH)
        expected = BLANK_CHOICE_DASH + [(str(em), em.value) for em in TestEnum]
        self.assertEqual(choices, expected) 
开发者ID:ashleywaite,项目名称:django-more,代码行数:7,代码来源:test_enumfield.py

示例7: test_manual_choices

# 需要导入模块: from django.db.models import fields [as 别名]
# 或者: from django.db.models.fields import BLANK_CHOICE_DASH [as 别名]
def test_manual_choices(self):
        members = [TestEnum.VAL1, TestEnum.VAL2]
        field = EnumField(TestEnum, choices=members)
        choices = field.get_choices(blank_choice=BLANK_CHOICE_DASH)
        expected = BLANK_CHOICE_DASH + [(str(em), em.value) for em in members]
        self.assertEqual(choices, expected) 
开发者ID:ashleywaite,项目名称:django-more,代码行数:8,代码来源:test_enumfield.py

示例8: get_action_choices

# 需要导入模块: from django.db.models import fields [as 别名]
# 或者: from django.db.models.fields import BLANK_CHOICE_DASH [as 别名]
def get_action_choices(self, request, default_choices=BLANK_CHOICE_DASH):
        """
        Return a list of choices for use in a form object.  Each choice is a
        tuple (name, description).
        """
        choices = [] + default_choices
        for func, name, description in self.get_actions(request).values():
            choice = (name, description % model_format_dict(self.opts))
            choices.append(choice)
        return choices 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:12,代码来源:options.py

示例9: _get_language_choices

# 需要导入模块: from django.db.models import fields [as 别名]
# 或者: from django.db.models.fields import BLANK_CHOICE_DASH [as 别名]
def _get_language_choices():
    return sorted(BLANK_CHOICE_DASH + get_available_admin_languages(),
                  key=lambda l: l[1].lower()) 
开发者ID:wagtail,项目名称:wagtail,代码行数:5,代码来源:forms.py

示例10: _get_time_zone_choices

# 需要导入模块: from django.db.models import fields [as 别名]
# 或者: from django.db.models.fields import BLANK_CHOICE_DASH [as 别名]
def _get_time_zone_choices():
    time_zones = [(tz, str(l18n.tz_fullnames.get(tz, tz)))
                  for tz in get_available_admin_time_zones()]
    time_zones.sort(key=itemgetter(1))
    return BLANK_CHOICE_DASH + time_zones 
开发者ID:wagtail,项目名称:wagtail,代码行数:7,代码来源:forms.py

示例11: _get_callable_choices

# 需要导入模块: from django.db.models import fields [as 别名]
# 或者: from django.db.models.fields import BLANK_CHOICE_DASH [as 别名]
def _get_callable_choices(self, choices, blank_choice=True):
        """
        Return a callable that we can pass into `forms.ChoiceField`, which will provide the
        choices list with the addition of a blank choice (if blank_choice=True and one does not
        already exist).
        """
        def choices_callable():
            # Variable choices could be an instance of CallableChoiceIterator, which may be wrapping
            # something we don't want to evaluate multiple times (e.g. a database query). Cast as a
            # list now to prevent it getting evaluated twice (once while searching for a blank choice,
            # once while rendering the final ChoiceField).
            local_choices = list(choices)

            # If blank_choice=False has been specified, return the choices list as is
            if not blank_choice:
                return local_choices

            # Else: if choices does not already contain a blank option, insert one
            # (to match Django's own behaviour for modelfields:
            # https://github.com/django/django/blob/1.7.5/django/db/models/fields/__init__.py#L732-744)
            has_blank_choice = False
            for v1, v2 in local_choices:
                if isinstance(v2, (list, tuple)):
                    # this is a named group, and v2 is the value list
                    has_blank_choice = any([value in ('', None) for value, label in v2])
                    if has_blank_choice:
                        break
                else:
                    # this is an individual choice; v1 is the value
                    if v1 in ('', None):
                        has_blank_choice = True
                        break

            if not has_blank_choice:
                return BLANK_CHOICE_DASH + local_choices

            return local_choices
        return choices_callable 
开发者ID:wagtail,项目名称:wagtail,代码行数:40,代码来源:field_block.py

示例12: setUp

# 需要导入模块: from django.db.models import fields [as 别名]
# 或者: from django.db.models.fields import BLANK_CHOICE_DASH [as 别名]
def setUp(self):
        from django.db.models.fields import BLANK_CHOICE_DASH
        self.blank_choice_dash_label = BLANK_CHOICE_DASH[0][1] 
开发者ID:wagtail,项目名称:wagtail,代码行数:5,代码来源:test_blocks.py

示例13: get_choices

# 需要导入模块: from django.db.models import fields [as 别名]
# 或者: from django.db.models.fields import BLANK_CHOICE_DASH [as 别名]
def get_choices(self, include_blank=True, blank_choice=BLANK_CHOICE_DASH,
                    limit_to_currently_related=False):
        """Returns choices with a default blank choices included, for use
        as SelectField choices for this field.

        Analogue of django.db.models.fields.Field.get_choices, provided
        initially for utilisation by RelatedFieldListFilter.
        """
        first_choice = include_blank and blank_choice or []
        queryset = self.model._default_manager.all()
        if limit_to_currently_related:
            queryset = queryset.complex_filter(
                {'%s__isnull' % self.parent_model._meta.module_name: False})
        lst = [(x._get_pk_val(), smart_text(x)) for x in queryset]
        return first_choice + lst 
开发者ID:blackye,项目名称:luscan-devel,代码行数:17,代码来源:related.py

示例14: get_option_label

# 需要导入模块: from django.db.models import fields [as 别名]
# 或者: from django.db.models.fields import BLANK_CHOICE_DASH [as 别名]
def get_option_label(self, value, choices=()):
        option_label = BLANK_CHOICE_DASH[0][1]

        for v, label in chain(self.choices, choices):
            if str(v) == value:
                option_label = label
                break

        if option_label == BLANK_CHOICE_DASH[0][1]:
            option_label = _('All')

        return option_label 
开发者ID:liqd,项目名称:adhocracy4,代码行数:14,代码来源:widgets.py

示例15: get_choices_with_blank_dash

# 需要导入模块: from django.db.models import fields [as 别名]
# 或者: from django.db.models.fields import BLANK_CHOICE_DASH [as 别名]
def get_choices_with_blank_dash(choices):
    return BLANK_CHOICE_DASH + list(choices) 
开发者ID:DheerendraRathor,项目名称:ldap-oauth2,代码行数:4,代码来源:utils.py


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