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


Python models.BLANK_CHOICE_DASH属性代码示例

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


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

示例1: _create_choices

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import BLANK_CHOICE_DASH [as 别名]
def _create_choices(self):
        """
        Adds objects of the selected model to the choices list.
        """
        # copy the empty choice
        # we shouldn't add choices to original list
        # also in that case BLANK_CHOICE_DASH would keep
        # all previously added choices
        choices = copy.copy(BLANK_CHOICE_DASH)
        # add objects only if the model class specified
        if self.model_class:
            items = self.model_class.objects.all()
            for item in items:
                choices.append((str(item.id), item))
        # replace original choices
        self.choices = choices 
开发者ID:Kemaweyan,项目名称:django-content-gallery,代码行数:18,代码来源:widgets.py

示例2: test_create_choices_objects_exist

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import BLANK_CHOICE_DASH [as 别名]
def test_create_choices_objects_exist(self):
        """
        Checks whether the _create_choices method creates choices for
        all objects of the selected model if objects exist. Also the list
        should include an empty choice.
        """
        # set selected model class with existing objects
        self.widget.model_class = TestModel
        # call the _create_choices method
        widgets.ObjectIdSelect._create_choices(self.widget)
        # check whether the list contains an empty choice
        self.assertIn(BLANK_CHOICE_DASH[0], self.widget.choices)
        # create choices
        choice1 = (str(self.object1.pk), self.object1)
        choice2 = (str(self.object2.pk), self.object2)
        # check whether the list contains both TestModel objects
        self.assertIn(choice1, self.widget.choices)
        self.assertIn(choice2, self.widget.choices)
        # check whether there are 3 choices so the list contains nothing
        # but two objects of the TestModel and an empty choice
        self.assertEqual(len(self.widget.choices), 3) 
开发者ID:Kemaweyan,项目名称:django-content-gallery,代码行数:23,代码来源:test_widgets.py

示例3: render_option

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models 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(selected) % {
            'attrs': selected and ' class="selected"' or '',
            'query_string': url,
            'name': name,
            'value': option_value,
            'label': force_text(option_label)
        } 
开发者ID:openlegaldata,项目名称:oldp,代码行数:21,代码来源:widgets.py

示例4: test_create_choices_objects_do_not_exist

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import BLANK_CHOICE_DASH [as 别名]
def test_create_choices_objects_do_not_exist(self):
        """
        Checks whether the _create_choices method creates an empty choice
        only if there is no objects of the selected model
        """
        # set selected model class without existing objects
        self.widget.model_class = AnotherTestModel
        # call the _create_choices method
        widgets.ObjectIdSelect._create_choices(self.widget)
        # check whether the list contains only one choice
        self.assertEqual(len(self.widget.choices), 1)
        # check whether an empty choice presents in the list
        self.assertIn(BLANK_CHOICE_DASH[0], self.widget.choices) 
开发者ID:Kemaweyan,项目名称:django-content-gallery,代码行数:15,代码来源:test_widgets.py

示例5: get_field_kwargs

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import BLANK_CHOICE_DASH [as 别名]
def get_field_kwargs(self, struct_value):
        kwargs = super().get_field_kwargs(struct_value)
        kwargs['choices'].insert(0, BLANK_CHOICE_DASH[0])
        return kwargs 
开发者ID:OpenTechFund,项目名称:hypha,代码行数:6,代码来源:blocks.py

示例6: __init__

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import BLANK_CHOICE_DASH [as 别名]
def __init__(self, *args, **kwargs):
        super(DomainAdminForm, self).__init__(*args, **kwargs)
        self.fields['master'].required = False
        self.fields['user'].required = False
        self.fields['user'].widget = forms.Select(
            choices=BLANK_CHOICE_DASH + [(i.id, i.username) for i in User.objects.all()]
        ) 
开发者ID:erigones,项目名称:esdc-ce,代码行数:9,代码来源:admin.py


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