Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding links to full change forms for inline items in django admin?

I have a standard admin change form for an object, with the usual StackedInline forms for a ForeignKey relationship. I would like to be able to link each inline item to its corresponding full-sized change form, as the inline item has inlined items of its own, and I can't nest them.

I've tried everything from custom widgets to custom templates, and can't make anything work. So far, the "solutions" I've seen in the form of snippets just plain don't seem to work for inlines. I'm getting ready to try some DOM hacking with jQuery just to get it working and move on.

I hope I must be missing something very simple, as this seems like such a simple task!

Using Django 1.2.

like image 680
David Eyk Avatar asked May 18 '10 12:05

David Eyk


2 Answers

There is a property called show_change_link since Django 1.8.

like image 159
Florian Avatar answered Oct 26 '22 13:10

Florian


I did something like the following in my admin.py:

from django.utils.html import format_html from django.core.urlresolvers import reverse  class MyModelInline(admin.TabularInline):     model = MyModel      def admin_link(self, instance):         url = reverse('admin:%s_%s_change' % (instance._meta.app_label,                                                 instance._meta.module_name),                       args=(instance.id,))         return format_html(u'<a href="{}">Edit</a>', url)         # … or if you want to include other fields:         return format_html(u'<a href="{}">Edit: {}</a>', url, instance.title)      readonly_fields = ('admin_link',) 
like image 37
Quentin Stafford-Fraser Avatar answered Oct 26 '22 13:10

Quentin Stafford-Fraser