Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

newforms-admin: Changed BoundInlineObject and templates to treat dele…

…tion, ordering, and pk fields as special cases for convenience. Also, changed StackedInline not to show a form row for the pk field.

git-svn-id: http://code.djangoproject.com/svn/django/branches/newforms-admin@5588 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 7c10d695278f080c020585c2dd2089c3f0dcceff 1 parent 836d2e7
@jkocherhans jkocherhans authored
View
25 django/contrib/admin/options.py
@@ -649,15 +649,12 @@ def __init__(self, inline_admin, formset):
def __iter__(self):
for form, original in zip(self.formset.change_forms, self.formset.get_inline_objects()):
- yield BoundInlineObject(form, original, self.inline_admin)
+ yield BoundInlineObject(self.formset, form, original, self.inline_admin)
for form in self.formset.add_forms:
- yield BoundInlineObject(form, None, self.inline_admin)
+ yield BoundInlineObject(self.formset, form, None, self.inline_admin)
def fields(self):
- # HACK: each form instance has some extra fields. Getting those fields
- # from the form class will take some rearranging. Get them from the
- # first form instance for now.
- return list(self.formset.forms[0])
+ return self.formset.form_class.base_fields.values()
def verbose_name(self):
return self.inline_admin.verbose_name
@@ -666,7 +663,8 @@ def verbose_name_plural(self):
return self.inline_admin.verbose_name_plural
class BoundInlineObject(object):
- def __init__(self, form, original, inline_admin):
+ def __init__(self, formset, form, original, inline_admin):
+ self.formset = formset
self.inline_admin = inline_admin
self.base_form = form
self.form = AdminForm(form, self.fieldsets(), inline_admin.prepopulated_fields)
@@ -682,8 +680,19 @@ def fieldsets(self):
given HttpRequest object.
"""
if self.inline_admin.fields is None:
- default_fields = [f for f in self.base_form.fields]
+ default_fields = [f for f in self.base_form.base_fields]
yield Fieldset(fields=default_fields)
else:
for name, options in self.opts.fields:
yield Fieldset(name, options['fields'], classes=options.get('classes', '').split(' '), description=options.get('description'))
+
+ def pk_field(self):
+ return BoundField(self.base_form, self.formset._pk_field_name, False)
+
+ def deletion_field(self):
+ from django.newforms.formsets import DELETION_FIELD_NAME
+ return BoundField(self.base_form, DELETION_FIELD_NAME, False)
+
+ def ordering_field(self):
+ from django.newforms.formsets import ORDERING_FIELD_NAME
+ return BoundField(self.base_form, ORDERING_FIELD_NAME, False)
View
2  django/contrib/admin/templates/admin/edit_inline_stacked.html
@@ -19,6 +19,8 @@
{% endfor %}
</div>
{% endfor %}
+ {{ bound_inline_object.pk_field.field }}
+ {% if bound_inline.formset.deletable %}<div class="form-row">{{ bound_inline_object.deletion_field.field }} {{ bound_inline_object.deletion_field.label_tag }}</div>{% endif %}
</fieldset>
{% endfor %}
</fieldset>
View
10 django/contrib/admin/templates/admin/edit_inline_tabular.html
@@ -3,6 +3,7 @@
<h2>{{ bound_inline.verbose_name_plural|capfirst|escape }}</h2>
<table>
<thead><tr>
+ {% if bound_inline.formset.deletable %}<th>Delete?</th>{% endif %}
{% for field in bound_inline.fields %}
{% if not field.is_hidden %}
<th>{{ field.label|capfirst|escape }}</th>
@@ -21,15 +22,12 @@
{% endif %}
<tr class="{% cycle row1,row2 %}">
+ {{ bound_inline_object.pk_field.field }}
+ {% if bound_inline.formset.deletable %}<td>{{ bound_inline_object.deletion_field.field }}</td>{% endif %}
{% for bfset in bound_inline_object.form %}
{% for line in bfset %}
{% for field in line %}
-
- {% if not field.field.is_hidden %}
- <td>{{ field.field }}</td>
- {% else %}
- {{ field.field }}
- {% endif %}
+ <td>{{ field.field }}</td>
{% endfor %}
{% endfor %}
{% endfor %}
View
3  django/newforms/models.py
@@ -267,7 +267,8 @@ def save(self, commit=True):
def add_fields(self, form, index):
"""Add a hidden field for the object's primary key."""
- form.fields[self.model._meta.pk.attname] = IntegerField(required=False, widget=HiddenInput)
+ self._pk_field_name = self.model._meta.pk.attname
+ form.fields[self._pk_field_name] = IntegerField(required=False, widget=HiddenInput)
super(BaseModelFormSet, self).add_fields(form, index)
def formset_for_model(model, form=BaseForm, formfield_callback=lambda f: f.formfield(), formset=BaseModelFormSet, extra=1, orderable=False, deletable=False, fields=None):
Please sign in to comment.
Something went wrong with that request. Please try again.