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