我们从Python开源项目中,提取了以下48个代码示例,用于说明如何使用django.forms.formsets.DELETION_FIELD_NAME。
def deletion_field(self): from django.forms.formsets import DELETION_FIELD_NAME return AdminField(self.form, DELETION_FIELD_NAME, False)
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 }
def get_attrs(self): fields = [] readonly_fields = [] if len(self.formset): fields = [f for k, f in list(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 }
def deletion_field(self): field = self[DELETION_FIELD_NAME] field.is_first = False return field
def hand_clean_DELETE(self): """ We don't validate the 'DELETE' field itself because on templates it's not rendered using the field information, but just using a generic "deletion_field" of the InlineModelAdmin. """ if self.cleaned_data.get(DELETION_FIELD_NAME, False): using = router.db_for_write(self._meta.model) collector = NestedObjects(using=using) if self.instance.pk is None: return collector.collect([self.instance]) if collector.protected: objs = [] for p in collector.protected: objs.append( # Translators: Model verbose name and instance representation, # suitable to be an item in a list. _('%(class_name)s %(instance)s') % { 'class_name': p._meta.verbose_name, 'instance': p} ) params = {'class_name': self._meta.model._meta.verbose_name, 'instance': self.instance, 'related_objects': get_text_list(objs, _('and'))} msg = _("Deleting %(class_name)s %(instance)s would require " "deleting the following protected related objects: " "%(related_objects)s") raise ValidationError(msg, code='deleting_protected', params=params)