Skip to content

Commit

Permalink
Implement show_change_link for Django 1.8 inlines. Related to #385. F…
Browse files Browse the repository at this point in the history
…ixes #366
  • Loading branch information
darklow committed Jul 23, 2015
1 parent 868b4ab commit 372e3e8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
10 changes: 8 additions & 2 deletions suit/templates/admin/edit_inline/stacked.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
{% load i18n admin_static %}
{% load i18n admin_static admin_urls suit_tags %}
{% suit_django_version as django_version %}
<div class="inline-group {{ inline_admin_formset.opts.suit_classes }}" id="{{ inline_admin_formset.formset.prefix }}-group">
<h2>{{ inline_admin_formset.opts.verbose_name_plural|capfirst }}</h2>
{{ inline_admin_formset.formset.management_form }}
{{ inline_admin_formset.formset.non_form_errors }}

{% for inline_admin_form in inline_admin_formset %}<div class="inline-related{% if forloop.last %} empty-form last-related{% endif %}" id="{{ inline_admin_formset.formset.prefix }}-{% if not forloop.last %}{{ forloop.counter0 }}{% else %}empty{% endif %}">
<h3><b>{{ inline_admin_formset.opts.verbose_name|title }}:</b>&nbsp;<span class="inline_label">{% if inline_admin_form.original %}{{ inline_admin_form.original }}{% else %}{% if not forloop.first and forloop.last %}#{{ forloop.counter }}{% endif %}{% endif %}</span>
<h3><b>{{ inline_admin_formset.opts.verbose_name|title }}:</b>&nbsp;<span class="inline_label">{% if inline_admin_form.original %}
{% if django_version > 1.7 and inline_admin_form.model_admin.show_change_link and inline_admin_form.model_admin.has_registered_model %} <a href="{% url inline_admin_form.model_admin.opts|admin_urlname:'change' inline_admin_form.original.pk|admin_urlquote %}" class="inlinechangelink">{{ inline_admin_form.original }}</a>
{% else %}
{{ inline_admin_form.original }}
{% endif %}
{% else %}{% if not forloop.first and forloop.last %}#{{ forloop.counter }}{% endif %}{% endif %}</span>
{% if inline_admin_form.show_url %}<a href="../../../r/{{ inline_admin_form.original_content_type_id }}/{{ inline_admin_form.original.id }}/">{% trans "View on site" %}</a>{% 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>
Expand Down
12 changes: 10 additions & 2 deletions suit/templates/admin/edit_inline/tabular.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{% load i18n admin_static admin_modify %}
{% load i18n admin_static admin_modify suit_tags admin_urls %}
{% suit_django_version as django_version %}
<div class="inline-group {{ inline_admin_formset.opts.suit_classes }}" id="{{ inline_admin_formset.formset.prefix }}-group">
<div class="tabular inline-related {% if forloop.last %}last-related{% endif %}">
{{ inline_admin_formset.formset.management_form }}
Expand All @@ -14,7 +15,8 @@ <h2>{{ inline_admin_formset.opts.verbose_name_plural|capfirst }}</h2>
</th>
{% endif %}
{% endfor %}
{% if inline_admin_formset.formset.can_delete %}<th>{% trans "Delete?" %}</th>{% endif %}
{% if inline_admin_formset.opts.show_change_link and inline_admin_formset.opts.has_registered_model %}<th class="text-center">{% trans "Change" %}</th>{% endif %}
{% if django_version > 1.7 and inline_admin_formset.formset.can_delete %}<th>{% trans "Delete?" %}</th>{% endif %}
</tr></thead>

<tbody>
Expand Down Expand Up @@ -60,6 +62,12 @@ <h2>{{ inline_admin_formset.opts.verbose_name_plural|capfirst }}</h2>
{% endfor %}
{% endfor %}
{% endfor %}
{% if django_version > 1.7 and inline_admin_form.model_admin.show_change_link and inline_admin_form.model_admin.has_registered_model %}
<td class="text-center">
{% if inline_admin_form.original %}
<p><a href="{% url inline_admin_form.model_admin.opts|admin_urlname:'change' inline_admin_form.original.pk|admin_urlquote %}" class="inlinechangelink">{% trans "Change" %}</a></p>
{% endif %}
</td>{% endif %}
{% if inline_admin_formset.formset.can_delete %}
<td class="delete">{% if inline_admin_form.original %}{{ inline_admin_form.deletion_field.field }}{% endif %}</td>
{% endif %}
Expand Down
5 changes: 5 additions & 0 deletions suit/templatetags/suit_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,8 @@ def suit_bc(*args):
@register.assignment_tag
def suit_bc_value(*args):
return utils.value_by_version(args)


@register.assignment_tag
def suit_django_version():
return utils.django_major_version()

0 comments on commit 372e3e8

Please sign in to comment.