當前位置: 首頁>>代碼示例>>Python>>正文


Python formsets.DELETION_FIELD_NAME屬性代碼示例

本文整理匯總了Python中django.forms.formsets.DELETION_FIELD_NAME屬性的典型用法代碼示例。如果您正苦於以下問題:Python formsets.DELETION_FIELD_NAME屬性的具體用法?Python formsets.DELETION_FIELD_NAME怎麽用?Python formsets.DELETION_FIELD_NAME使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在django.forms.formsets的用法示例。


在下文中一共展示了formsets.DELETION_FIELD_NAME屬性的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_attrs

# 需要導入模塊: from django.forms import formsets [as 別名]
# 或者: from django.forms.formsets import DELETION_FIELD_NAME [as 別名]
def get_attrs(self):
        fields = []
        readonly_fields = []
        if len(self.formset):
            fields = [f for k, f in self.formset[0].fields.items() if k != DELETION_FIELD_NAME]
            readonly_fields = [f for f in getattr(self.formset[0], 'readonly_fields', [])]
        return {
            'fields': fields,
            'readonly_fields': readonly_fields
        } 
開發者ID:stormsha,項目名稱:StormOnline,代碼行數:12,代碼來源:inline.py

示例2: deletion_field

# 需要導入模塊: from django.forms import formsets [as 別名]
# 或者: from django.forms.formsets import DELETION_FIELD_NAME [as 別名]
def deletion_field(self):
        from django.forms.formsets import DELETION_FIELD_NAME
        return AdminField(self.form, DELETION_FIELD_NAME, False) 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:5,代碼來源:helpers.py

示例3: on_form_bound

# 需要導入模塊: from django.forms import formsets [as 別名]
# 或者: from django.forms.formsets import DELETION_FIELD_NAME [as 別名]
def on_form_bound(self):
        self.formset = self.form.formsets[self.relation_name]

        self.children = []
        for subform in self.formset.forms:
            # override the DELETE field to have a hidden input
            subform.fields[DELETION_FIELD_NAME].widget = forms.HiddenInput()

            # ditto for the ORDER field, if present
            if self.formset.can_order:
                subform.fields[ORDERING_FIELD_NAME].widget = forms.HiddenInput()

            child_edit_handler = self.get_child_edit_handler()
            self.children.append(child_edit_handler.bind_to(
                instance=subform.instance, request=self.request, form=subform))

        # if this formset is valid, it may have been re-ordered; respect that
        # in case the parent form errored and we need to re-render
        if self.formset.can_order and self.formset.is_valid():
            self.children.sort(
                key=lambda child: child.form.cleaned_data[ORDERING_FIELD_NAME] or 1)

        empty_form = self.formset.empty_form
        empty_form.fields[DELETION_FIELD_NAME].widget = forms.HiddenInput()
        if self.formset.can_order:
            empty_form.fields[ORDERING_FIELD_NAME].widget = forms.HiddenInput()

        self.empty_child = self.get_child_edit_handler()
        self.empty_child = self.empty_child.bind_to(
            instance=empty_form.instance, request=self.request, form=empty_form) 
開發者ID:wagtail,項目名稱:wagtail,代碼行數:32,代碼來源:edit_handlers.py

示例4: clean

# 需要導入模塊: from django.forms import formsets [as 別名]
# 或者: from django.forms.formsets import DELETION_FIELD_NAME [as 別名]
def clean(self):
        super().clean()
        if any(self.errors):
            return

        dates = []

        for form in self.forms:
            if form.cleaned_data:
                date = form.cleaned_data['date']
                delete = form.cleaned_data[DELETION_FIELD_NAME]
                if date and not delete:
                    self.validate_date(date, dates)
                    dates.append(date) 
開發者ID:eventoL,項目名稱:eventoL,代碼行數:16,代碼來源:forms.py

示例5: add_fields

# 需要導入模塊: from django.forms import formsets [as 別名]
# 或者: from django.forms.formsets import DELETION_FIELD_NAME [as 別名]
def add_fields(self, form, index):
        super().add_fields(form, index)
        form.fields[DELETION_FIELD_NAME].widget = forms.HiddenInput() 
開發者ID:wagtail,項目名稱:wagtail-review,代碼行數:5,代碼來源:forms.py

示例6: add_fields

# 需要導入模塊: from django.forms import formsets [as 別名]
# 或者: from django.forms.formsets import DELETION_FIELD_NAME [as 別名]
def add_fields(self, form, index):
        super().add_fields(form, index)
        self.can_delete = True
        if DELETION_FIELD_NAME in form.fields:
            del form.fields[DELETION_FIELD_NAME] 
開發者ID:nesdis,項目名稱:djongo,代碼行數:7,代碼來源:tests.py

示例7: get_fromset_fields

# 需要導入模塊: from django.forms import formsets [as 別名]
# 或者: from django.forms.formsets import DELETION_FIELD_NAME [as 別名]
def get_fromset_fields(self, formset):
        fields = list(self.generate_fields() or formset.form.base_fields.keys())
        if formset.can_delete:
            fields.append(DELETION_FIELD_NAME)
        return fields 
開發者ID:matllubos,項目名稱:django-is-core,代碼行數:7,代碼來源:inline_form_views.py

示例8: get_formset

# 需要導入模塊: from django.forms import formsets [as 別名]
# 或者: from django.forms.formsets import DELETION_FIELD_NAME [as 別名]
def get_formset(self):
        fields = self.generate_fields()
        readonly_fields = self.generate_readonly_fields()

        if self.request.POST:
            formset = self.get_formset_factory(fields, readonly_fields)(data=self.request.POST,
                                                                        files=self.request.FILES,
                                                                        instance=self.parent_instance,
                                                                        queryset=self.get_queryset(),
                                                                        prefix=self.get_prefix())
        else:
            formset = self.get_formset_factory(fields, readonly_fields)(instance=self.parent_instance,
                                                                        queryset=self.get_queryset(),
                                                                        initial=self.get_initial(),
                                                                        prefix=self.get_prefix())

        formset.can_add = self.get_can_add()
        for form in formset.all_forms():
            form.class_names = self.form_class_names(form)
            form._is_readonly = self.is_form_readonly(form)
            if not self.readonly and form._is_readonly:
                if formset.can_delete:
                    form.readonly_fields = set(form.fields.keys()) - {'id', DELETION_FIELD_NAME}
                else:
                    form.readonly_fields = set(form.fields.keys()) - {'id'}

            if formset.can_delete and form.instance.pk and not self.can_form_delete(form):
                form.fields[DELETION_FIELD_NAME] = EmptyReadonlyField(
                    required=form.fields[DELETION_FIELD_NAME].required,
                    label=form.fields[DELETION_FIELD_NAME].label
                )
                form.readonly_fields |= {DELETION_FIELD_NAME}

            self.init_form(form)

        for i in range(self.get_min_num()):
            formset.forms[i].empty_permitted = False
        return formset 
開發者ID:matllubos,項目名稱:django-is-core,代碼行數:40,代碼來源:inline_form_views.py


注:本文中的django.forms.formsets.DELETION_FIELD_NAME屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。