Opened 5 years ago

Closed 8 months ago

#13163 closed New feature (fixed)

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

Reported by: DrMeers Owned by: DrMeers
Component: contrib.admin Version: master
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 DrMeers 5 years ago.
InlineAdminForm changes, stacked/tabular template updates and regression tests
combined_13163_13165.diff (24.0 KB) - added by DrMeers 5 years ago.
Combined patch for #113163 and #13165
combined_13165_13165.diff (24.0 KB) - added by DrMeers 5 years ago.
Added unicode fix
inline_edit_link.diff (2.1 KB) - added by dperetti 4 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 3 years ago.
modifed version edit_inline_link.diff that supports inlined models from other apps

Download all attachments as: .zip

Change History (27)

Changed 5 years ago by DrMeers

InlineAdminForm changes, stacked/tabular template updates and regression tests

comment:1 Changed 5 years ago by kmtracey

  • milestone 1.2 deleted
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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

comment:2 Changed 5 years ago by russellm

  • Component changed from django.contrib.admin to User Experience
  • Owner nobody deleted
  • Triage Stage changed from Unreviewed to Accepted

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

comment:3 Changed 5 years ago by DrMeers

  • Owner set to DrMeers
  • Status changed from new to assigned

Changed 5 years ago by DrMeers

Combined patch for #113163 and #13165

comment:4 Changed 5 years ago by DrMeers

  • milestone set to 1.3

Changed 5 years ago by DrMeers

Added unicode fix

comment:5 Changed 4 years ago by anonymous

  • Cc sree@… added

comment:6 Changed 4 years ago by EnTeQuAk

  • Cc cg@… added

comment:7 Changed 4 years ago by lukeplant

  • Type set to New feature

comment:8 Changed 4 years ago by lukeplant

  • Severity set to Normal

comment:9 Changed 4 years ago by anonymous

  • Easy pickings unset

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

comment:10 Changed 4 years ago by patchhammer

  • Patch needs improvement set

combined_13165_13165.diff fails to apply cleanly on to trunk

comment:11 Changed 4 years ago by julien

  • UI/UX set

comment:12 Changed 4 years ago by julien

  • Component changed from User Experience to contrib.admin

Changed 4 years ago by dperetti

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

comment:13 Changed 4 years ago by dperetti

  • 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 Changed 3 years ago by jacob

  • milestone 1.3 deleted

Milestone 1.3 deleted

comment:15 Changed 3 years ago by anonymous

any chance this will make it into 1.4 ?

comment:16 Changed 3 years ago by anonymous

still waiting for this to become a feature.

comment:17 Changed 3 years ago by glicerinu@…

  • Cc glicerinu@… added

comment:18 Changed 3 years ago by charettes

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.

Changed 3 years ago by smcoll

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

comment:19 Changed 9 months ago by blueyed

@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 Changed 8 months ago by slurms

  • 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 Changed 8 months ago by slurms

  • Needs documentation unset

Added docs, updated PR.

comment:22 Changed 8 months ago by Tim Graham <timograham@…>

  • Resolution set to fixed
  • Status changed from assigned to closed

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