Skip to content

Commit e9b2fc1

Browse files
committed
[soc2009/admin-ui] One step further to adding inlines using javascript.
This time, we clone the first hidden extra-inline field, append it to the inline list, and update its id. This is actually a pretty terrible way to add inlines, but it serves the purpose of showing what an addition will look like. git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2009/admin-ui@10940 bcc190cf-cafb-0310-a4f2-bffc1f526a37
1 parent 6252301 commit e9b2fc1

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

django/contrib/admin/options.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,6 @@ def change_view(self, request, object_id, extra_context=None):
868868
'root_path': self.admin_site.root_path,
869869
'app_label': opts.app_label,
870870
}
871-
#import ipdb; ipdb.set_trace()
872871
context.update(extra_context or {})
873872
return self.render_change_form(request, context, change=True, obj=obj)
874873
change_view = transaction.commit_on_success(change_view)

django/contrib/admin/templates/admin/edit_inline/stacked.html

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{% load i18n %}
2-
<div class="inline-group">
2+
<div class="inline-group" id="{{ inline_admin_formset.opts.verbose_name}}-group">
33
<h2>{{ inline_admin_formset.opts.verbose_name_plural|title }}</h2>
44
{{ inline_admin_formset.formset.management_form }}
55
{{ inline_admin_formset.formset.non_form_errors }}
@@ -47,8 +47,15 @@ <h3><b>{{ inline_admin_formset.opts.verbose_name|title }}:</b>&nbsp;{% if inline
4747

4848
// clicking on the "add" link will add a blank form to add a new inline object
4949
$('#' + id_prefix + "-add").click(function() {
50+
{# TODO Zain: this will not work if extra = 0 for the inline #}
5051
total_forms++;
51-
$('#' + id_prefix + (total_forms)).show();
52+
53+
// clone the first hidden extra-inline field and append it to the inline list
54+
$('#' + id_prefix + (initial_forms + 1)).clone().fadeIn('normal')
55+
.insertAfter('#' + id_prefix + "-group .inline-related:last")
56+
.attr("id", id_prefix + total_forms)
57+
58+
return false;
5259
});
5360
});
5461
</script>

0 commit comments

Comments
 (0)