當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。