Opened 15 years ago

Closed 10 years ago

#13163 closed New feature (fixed)

Display link to change-form on inlines where model is registered in admin site

Reported by: Simon Meers Owned by: Simon Meers
Component: contrib.admin Version: dev
Severity: Normal Keywords: inline link
Cc: sree@…, cg@…, glicerinu@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: yes

Description

If an inline object has a get_absolute_url method, a 'View on site' link is displayed.

Here I propose that if an inline object is registered in the same admin site, an 'Edit' link is displayed in a similar fashion.

Why?

  • The inline may only display a subset of fields, so the user may wish to go to the full change form
  • 'Recursive inlines' can be accessed more easily -- e.g. Household has Person inlines, and Person has Phone inlines, etc.

The attached patch shows a draft implementation.

Questions:

  • Do we need to check if the user has change permissions on that model before displaying the link? (in the unlikely event that the user has permission to change a model which displays the inlines of a model which they do not have change permissions for). Given that I cannot see a straightforward way of checking for this without the addition of a template tag/filter, and the rarity of such setups, I'd be happy to let the user click the link and get a permission denied page.
  • Do we need an InlineModelAdmin option for enabling/disabling this link? E.g. InlineModelAdmin.show_admin_link. Or are we happy to have it enabled globally?
  • Is [ Edit ] a sufficiently understandable link label? Would "Edit in Admin", or "Display full form" or something be more appropriate?

I think the reciprocal of this would also be very useful -- ForeignKey widgets could display an [edit] link beside the "add new" (green +) link which links to the change form for the selected parent object.

Attachments (5)

admin_url.diff (8.2 KB ) - added by Simon Meers 15 years ago.
InlineAdminForm changes, stacked/tabular template updates and regression tests
combined_13163_13165.diff (24.0 KB ) - added by Simon Meers 15 years ago.
Combined patch for #113163 and #13165
combined_13165_13165.diff (24.0 KB ) - added by Simon Meers 14 years ago.
Added unicode fix
inline_edit_link.diff (2.1 KB ) - added by Dominique PERETTI 14 years ago.
Add show_edit_link = True to your ObjectInline and you get an edit link
inline_edit_link-2.diff (2.0 KB ) - added by smcoll 12 years ago.
modifed version edit_inline_link.diff that supports inlined models from other apps

Download all attachments as: .zip

Change History (27)

by Simon Meers, 15 years ago

Attachment: admin_url.diff added

InlineAdminForm changes, stacked/tabular template updates and regression tests

comment:1 by Karen Tracey, 15 years ago

milestone: 1.2

This is a feature request and thus not appropriate for the 1.2 milestone at this point.

comment:2 by Russell Keith-Magee, 15 years ago

Component: django.contrib.adminUser Experience
Owner: nobody removed
Triage Stage: UnreviewedAccepted

Sounds like a reasonable idea; reassigning to UX because it reflects on the UX of the admin, not admin code itself.

comment:3 by Simon Meers, 15 years ago

Owner: set to Simon Meers
Status: newassigned

by Simon Meers, 15 years ago

Attachment: combined_13163_13165.diff added

Combined patch for #113163 and #13165

comment:4 by Simon Meers, 15 years ago

milestone: 1.3

by Simon Meers, 14 years ago

Attachment: combined_13165_13165.diff added

Added unicode fix

comment:5 by anonymous, 14 years ago

Cc: sree@… added

comment:6 by Christopher Grebs, 14 years ago

Cc: cg@… added

comment:7 by Luke Plant, 14 years ago

Type: New feature

comment:8 by Luke Plant, 14 years ago

Severity: Normal

comment:9 by anonymous, 14 years ago

Easy pickings: unset

With Django 1.3 does not work. Is there anything like that under 1.3 ?

comment:10 by patchhammer, 14 years ago

Patch needs improvement: set

combined_13165_13165.diff fails to apply cleanly on to trunk

comment:11 by Julien Phalip, 14 years ago

UI/UX: set

comment:12 by Julien Phalip, 14 years ago

Component: User Experiencecontrib.admin

by Dominique PERETTI, 14 years ago

Attachment: inline_edit_link.diff added

Add show_edit_link = True to your ObjectInline and you get an edit link

comment:13 by Dominique PERETTI, 14 years ago

Needs tests: set

Hey guys, I've just added above my own implementation of this feature. Very simple, just 3 lines of code but does the job.
(This patch does it only in tabular.html).

class BooksInline(admin.TabularInline):
	model = Book
	show_edit_link = True

comment:14 by Jacob, 13 years ago

milestone: 1.3

Milestone 1.3 deleted

comment:15 by anonymous, 13 years ago

any chance this will make it into 1.4 ?

comment:16 by anonymous, 13 years ago

still waiting for this to become a feature.

comment:17 by glicerinu@…, 13 years ago

Cc: glicerinu@… added

comment:18 by Simon Charette, 13 years ago

I packaged a simple app providing admin mixins to add a the edition and deletion links on all amin FK widgets, including those in inlines. You can find the project on github and on pypi.

by smcoll, 12 years ago

Attachment: inline_edit_link-2.diff added

modifed version edit_inline_link.diff that supports inlined models from other apps

comment:19 by Daniel Hahler, 11 years ago

@smcoll:

It looks like there is a wrong if in your patch: {% if inline_admin_form.original %}. It should check for the new show_edit_link option probably.

I assume that it won't work for many2many inlines, where you have model = Foo.bars.through?

comment:20 by Nick Sandford, 10 years ago

Needs documentation: set
Needs tests: unset
Patch needs improvement: unset

PR here: https://github.com/django/django/pull/2957.

I added a method AdminSite.is_registered() which takes a Model class or lowercased model name. This is needed for checking if the InlineModelAdmin's model is also registered as a ModelAdmin on the site. There is precedence for this sort of check with registries -- the app registry has apps.is_installed(), and it seems to be a reasonable method to have on the AdminSite.

Renamed the show_edit_link to show_change_link for consistency across the admin. The link will only be displayed if show_change_link = True on the inline, the model itself is also registered, and there is an inline object to change.

comment:21 by Nick Sandford, 10 years ago

Needs documentation: unset

Added docs, updated PR.

comment:22 by Tim Graham <timograham@…>, 10 years ago

Resolution: fixed
Status: assignedclosed

In 9d9f0acd7e245c9f9c30727a003666618754c924:

Fixed #13163 -- Added ability to show change links on inline objects in admin.

Thanks DrMeers for the suggestion.

Note: See TracTickets for help on using tickets.
Back to Top