1
0
mirror of https://github.com/django/django.git synced 2025-07-04 01:39:20 +00:00

[soc2009/admin-ui] First steps to dynamically add stacked inlines. Upon loading the change list page, all extra inline fields are hidden and an "Add" link is shown at the bottom.

Currently, clicking on the link will only re-show the hidden extra inlines; it won't add any new ones. Proper addition is going to be in the next check-in.


git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2009/admin-ui@10939 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Zain Memon 2009-06-07 07:05:27 +00:00
parent d3e2863e89
commit 62523016cc
3 changed files with 35 additions and 5 deletions

View File

@ -325,3 +325,6 @@ fieldset.monospace textarea {
padding-left: 14px;
}
.add_inline {
display: none;
}

View File

@ -868,6 +868,7 @@ class ModelAdmin(BaseModelAdmin):
'root_path': self.admin_site.root_path,
'app_label': opts.app_label,
}
#import ipdb; ipdb.set_trace()
context.update(extra_context or {})
return self.render_change_form(request, context, change=True, obj=obj)
change_view = transaction.commit_on_success(change_view)
@ -1122,7 +1123,7 @@ class InlineModelAdmin(BaseModelAdmin):
def _media(self):
from django.conf import settings
js = []
js = ['js/jquery.js']
if self.prepopulated_fields:
js.append('js/urlify.js')
if self.filter_vertical or self.filter_horizontal:

View File

@ -5,7 +5,7 @@
{{ inline_admin_formset.formset.non_form_errors }}
{% for inline_admin_form in inline_admin_formset %}
<div class="inline-related{% if forloop.last %} last-related{% endif %}">
<div class="inline-related{% if forloop.last %} last-related{% endif %}" id="{{ inline_admin_formset.opts.verbose_name}}{{ forloop.counter }}">
<h3><b>{{ inline_admin_formset.opts.verbose_name|title }}:</b>&nbsp;{% if inline_admin_form.original %}{{ inline_admin_form.original }}{% else %} #{{ forloop.counter }}{% endif %}
{% if inline_admin_formset.formset.can_delete and inline_admin_form.original %}<span class="delete">{{ inline_admin_form.deletion_field.field }} {{ inline_admin_form.deletion_field.label_tag }}</span>{% endif %}
</h3>
@ -22,7 +22,33 @@
</div>
{% endfor %}
{# <ul class="tools"> #}
{# <li><a class="add" href="">Add another {{ inline_admin_formset.opts.verbose_name|title }}</a></li> #}
{# </ul> #}
<ul class="tools add_inline">
<li><a id="{{ inline_admin_formset.opts.verbose_name }}-add" class="add" href="#">Add a {{ inline_admin_formset.opts.verbose_name }}</a></li>
</ul>
</div>
<script type="text/javascript">
$(function() {
{# TODO Zain: properly set the TOTAL_FORMS hidden input field #}
var id_prefix = "{{ inline_admin_formset.opts.verbose_name }}";
var total_forms = {{ inline_admin_formset.formset.management_form.initial.TOTAL_FORMS }};
var initial_forms = {{ inline_admin_formset.formset.management_form.initial.INITIAL_FORMS }};
// since javascript is turned on, unhide the "add new <inline>" link and hide the extras
$('.add_inline').show();
for(var i = initial_forms + 1; i <= total_forms; i++) {
$('#' + id_prefix + i).hide();
}
total_forms = initial_forms;
// clicking on the "add" link will add a blank form to add a new inline object
$('#' + id_prefix + "-add").click(function() {
total_forms++;
$('#' + id_prefix + (total_forms)).show();
});
});
</script>