本文整理匯總了Python中django.forms.formsets.ORDERING_FIELD_NAME屬性的典型用法代碼示例。如果您正苦於以下問題:Python formsets.ORDERING_FIELD_NAME屬性的具體用法?Python formsets.ORDERING_FIELD_NAME怎麽用?Python formsets.ORDERING_FIELD_NAME使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類django.forms.formsets
的用法示例。
在下文中一共展示了formsets.ORDERING_FIELD_NAME屬性的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: ordering_field
# 需要導入模塊: from django.forms import formsets [as 別名]
# 或者: from django.forms.formsets import ORDERING_FIELD_NAME [as 別名]
def ordering_field(self):
from django.forms.formsets import ORDERING_FIELD_NAME
return AdminField(self.form, ORDERING_FIELD_NAME, False)
示例2: on_form_bound
# 需要導入模塊: from django.forms import formsets [as 別名]
# 或者: from django.forms.formsets import ORDERING_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)