diff --git a/django/contrib/admin/templates/admin/edit_inline_tabular.html b/django/contrib/admin/templates/admin/edit_inline_tabular.html
index e9535df02c..5e51b3772b 100644
--- a/django/contrib/admin/templates/admin/edit_inline_tabular.html
+++ b/django/contrib/admin/templates/admin/edit_inline_tabular.html
@@ -7,6 +7,8 @@
{{ fw.field.verbose_name|capfirst }}
{% endif %}
{% endfor %}
+
+
{% for fcw in bound_related_object.form_field_collection_wrappers %}
{% if change %}{% if original_row_needed %}
{% if fcw.obj.original %}
@@ -29,10 +31,14 @@
{% if bound_related_object.show_url %}
{% if fcw.obj.original %}View on site {% endif %}
{% endif %}
+
+ Delete
+
{% endfor %}
-
+ Add
+
{% for fcw in bound_related_object.form_field_collection_wrappers %}
{% for bound_field in fcw.bound_fields %}
{% if bound_field.hidden %}
diff --git a/django/contrib/admin/views/stages/change.py b/django/contrib/admin/views/stages/change.py
index c8dd5be8bb..39eda8f3e9 100644
--- a/django/contrib/admin/views/stages/change.py
+++ b/django/contrib/admin/views/stages/change.py
@@ -36,9 +36,9 @@ def change_stage(request, path, object_id):
raise PermissionDenied
if request.POST and request.POST.has_key("_saveasnew"):
return add_stage(request, path, form_url='../../add/')
+
try:
- manipulator_class = model.ChangeManipulator
- manipulator = manipulator_class(object_id)
+ manipulator = model.ChangeManipulator(object_id)
except ObjectDoesNotExist:
raise Http404
@@ -50,26 +50,31 @@ def change_stage(request, path, object_id):
errors = manipulator.get_validation_errors(new_data)
manipulator.do_html2python(new_data)
- if not errors and not request.POST.has_key("_preview"):
- new_object = manipulator.save(new_data)
- log_change_message(request.user, opts, manipulator, new_object)
- msg = _('The %(name)s "%(obj)s" was changed successfully.') % {'name': opts.verbose_name, 'obj': new_object}
- pk_value = getattr(new_object, opts.pk.attname)
- if request.POST.has_key("_continue"):
- request.user.add_message(msg + ' ' + _("You may edit it again below."))
- if request.REQUEST.has_key('_popup'):
- return HttpResponseRedirect(request.path + "?_popup=1")
+ if not errors:
+ if request.POST.has_key("command"):
+ command_name = request.POST.get("command")
+ manipulator.do_command(new_data, command_name)
+ new_data = manipulator.flatten_data()
+ elif not request.POST.has_key("_preview"):
+ new_object = manipulator.save(new_data)
+ log_change_message(request.user, opts, manipulator, new_object)
+ msg = _('The %(name)s "%(obj)s" was changed successfully.') % {'name': opts.verbose_name, 'obj': new_object}
+ pk_value = getattr(new_object, opts.pk.attname)
+ if request.POST.has_key("_continue"):
+ request.user.add_message(msg + ' ' + _("You may edit it again below."))
+ if request.REQUEST.has_key('_popup'):
+ return HttpResponseRedirect(request.path + "?_popup=1")
+ else:
+ return HttpResponseRedirect(request.path)
+ elif request.POST.has_key("_saveasnew"):
+ request.user.add_message(_('The %(name)s "%(obj)s" was added successfully. You may edit it again below.') % {'name': opts.verbose_name, 'obj': new_object})
+ return HttpResponseRedirect("../../%s/" % pk_value)
+ elif request.POST.has_key("_addanother"):
+ request.user.add_message(msg + ' ' + (_("You may add another %s below.") % opts.verbose_name))
+ return HttpResponseRedirect("../../add/")
else:
- return HttpResponseRedirect(request.path)
- elif request.POST.has_key("_saveasnew"):
- request.user.add_message(_('The %(name)s "%(obj)s" was added successfully. You may edit it again below.') % {'name': opts.verbose_name, 'obj': new_object})
- return HttpResponseRedirect("../../%s/" % pk_value)
- elif request.POST.has_key("_addanother"):
- request.user.add_message(msg + ' ' + (_("You may add another %s below.") % opts.verbose_name))
- return HttpResponseRedirect("../../add/")
- else:
- request.user.add_message(msg)
- return HttpResponseRedirect("../../")
+ request.user.add_message(msg)
+ return HttpResponseRedirect("../../")
else:
# Populate new_data with a "flattened" version of the current data.
new_data = manipulator.flatten_data()
diff --git a/django/db/models/manipulators.py b/django/db/models/manipulators.py
index 78d0970f55..2ffd22e8c1 100644
--- a/django/db/models/manipulators.py
+++ b/django/db/models/manipulators.py
@@ -47,7 +47,7 @@ class ManipulatorHelper(object):
self.related_collection = related_collection
class FillHelper(ManipulatorHelper):
- def matched_item(self,child_manip, obj_data):
+ def matched_item(self,index, child_manip, obj_data):
child_manip._fill_data(obj_data)
def missing_item(self, index, child_manip):
@@ -155,51 +155,58 @@ class AutomaticManipulator(Manipulator):
helper.new_item(obj_data)
def _fill_data(self, expanded_data):
- self.original_object = self.get_new_object()
+ self.original_object = self.get_new_object(expanded_data)
# TODO: many_to_many
self._fill_related_objects(expanded_data,FillHelper)
def do_command(self, new_data, command):
expanded_data = dot_expand(new_data, MultiValueDict)
# Deal with the effects of previous commands
- self.fill_data(expanded_data)
+ self._fill_data(expanded_data)
# Do this command
command_parts = command.split('.')
- self._do_command_expanded(self, expanded_data, command_parts)
+ self._do_command_expanded(expanded_data, command_parts)
def _do_command_expanded(self, expanded_data, command_parts):
- part = command_parts.pop(0, None)
- if part == None:
+ try:
+ part = command_parts.pop(0)
+ except IndexError:
raise BadCommand, "Not enough parts in command"
# must be the name of a child manipulator collection
child_manips = None
related = None
- for rel,manips in self.children:
+ for rel,manips in self.children.items():
if rel.var_name == part:
related = rel
child_manips = manips
break
if child_manips == None:
- raise BadCommand, "%s : unknown manipulator collection name." % (part,)
+ raise BadCommand, "'%s' : unknown manipulator collection name." % (part,)
child_data = expanded_data.get(part, None)
if child_data == None:
- raise BadCommand, "%s : could not find data for manipulator collection." % (part,)
+ raise BadCommand, "'%s' : could not find data for manipulator collection." % (part,)
# The next part could be an index of a manipulator,
# or it could be a command on the collection.
- index_part = command_parts.pop(0)
+ try:
+ part = command_parts.pop(0)
+ except IndexError:
+ raise BadCommand, "Not enough parts in command"
try:
index = int(index_part)
manip = child_manips.get(index, None)
+
if manip == None:
raise BadCommand, "No %s manipulator found for index %s in command." % (part, index)
-
+ obj_data = child_data.get(index_part, None)
+ if obj_data == None:
+ raise BadCommand, "Could not find data for manipulator %s in %s collection." % (index, part)
if command_parts == ["delete"]:
child_manips[index] = None
else:
- manip._do_command_expanded(expanded_data,command_parts)
+ manip._do_command_expanded(obj_data,command_parts)
except ValueError:
# Must be a command on the collection. Possible commands:
# add.
diff --git a/django/db/models/related.py b/django/db/models/related.py
index 14256e5f43..03b2737549 100644
--- a/django/db/models/related.py
+++ b/django/db/models/related.py
@@ -87,32 +87,10 @@ class RelatedObject(object):
manipulators = []
for i,obj in enumerate(list):
- prefix = '%s.%d.' % (self.var_name, i)
+ prefix = '%s%s.%d.' % (parent_manipulator.name_prefix, self.var_name, i)
manipulators.append(man_class(obj,follow, prefix) )
return manipulators
- def get_manipulator_fields(self, opts, manipulator, follow):
- # TODO: Remove core fields stuff.
- change = manipulator.change
- if manipulator.original_object:
- meth_name = 'get_%s_count' % self.get_method_name_part()
- count = getattr(manipulator.original_object, meth_name)()
-
- count += self.field.rel.num_extra_on_change
- if self.field.rel.min_num_in_admin:
- count = max(count, self.field.rel.min_num_in_admin)
- if self.field.rel.max_num_in_admin:
- count = min(count, self.field.rel.max_num_in_admin)
- else:
- count = self.field.rel.num_in_admin
- fields = []
-
- for i in range(count):
- for f in self.opts.fields + self.opts.many_to_many:
- if follow.get(f.name, False):
- prefix = '%s.%d.' % (self.var_name, i)
- fields.extend(f.get_manipulator_fields(self.opts, manipulator, change, name_prefix=prefix, rel=True))
- return fields
def bind(self, field_mapping, original, bound_related_object_class=BoundRelatedObject):
return bound_related_object_class(self, field_mapping, original)