Opened 13 years ago

Closed 9 years ago

#2569 closed enhancement (duplicate)

[patch] Admin page Foreign Key improvements

Reported by: joelh-django@… Owned by: nobody
Component: contrib.admin Version: master
Severity: normal Keywords:
Cc: pythonmailing@… Triage Stage: Someday/Maybe
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


This patch provides two changes to the admin page. Firstly, one-to-one mappings can now be clicked on to be taken to that object. Secondly a new button allows you to edit a foreign key object in same way that you can add one.

The reason for this is that we are using the django admin page to make an asset tracker, and so far I've been impressed by how powerful the admin pages are. Unfortunately with highly normalized data its a pain to have so few paths for getting to objects. This patch should streamline the process a bit.

At the moment I have the looking glass icon to denote editing the element. Probably want to use a new edit icon. I'll attach one to this ticket if I can get a friend to make one.

Attachments (4)

adminforeign.diff (4.4 KB) - added by joelh-django@… 13 years ago.
diff file for the patch
adminforeign.2.diff (4.2 KB) - added by joelh-django@… 13 years ago.
diff file for the patch
adminforeign.3.diff (5.1 KB) - added by Joel Heenan <joelh-django@…> 13 years ago.
adminforeign.2.rev6000.diff (3.1 KB) - added by Marek Kubica <pythonmailing@…> 12 years ago.
The adminforeign.2.diff ported to SVN revision 6000

Download all attachments as: .zip

Change History (11)

Changed 13 years ago by joelh-django@…

Attachment: adminforeign.diff added

diff file for the patch

Changed 13 years ago by joelh-django@…

Attachment: adminforeign.2.diff added

diff file for the patch

comment:1 Changed 13 years ago by jim-django@…

Hi Joel;

I like the idea of these extra navigation links quite a lot; but I had a few problems with the patch.

First, one-to-one field related links are broken. They expect the bound field's existing_display method to return the related object's primary key; this is not the case - they return the related object itself. This might work if the related object's str returns it's primary key, but that's definitely not the case for most of my models. I had to add a related_key field with the related object's primary key in AdminBoundField.

Secondly, it expectes ADD_SLASHES to be turned on - which it is by default, but wasn't on my machine. This incurs a redirection everytime you click on a related item link, though, and can be fixed by adding "/" to the path in the showEditPopup javascript function.

Also, it would be nice if links were available on both sides of a one-to-one relationship. It looks like that might be a lot more work though.

Changed 13 years ago by Joel Heenan <joelh-django@…>

Attachment: adminforeign.3.diff added


comment:2 Changed 13 years ago by Joel Heenan <joelh-django@…>


Well spotted on those issues - I've now fixed both. I made a slight change to the javascript which means it now works with inline fields.

I agree it would be very nice to have a link back for one-to-one fields that reference this object. But then this would probably be useful not just for one-to-one fields but also for any type of related field and it probably should have its own separate place in the admin page.

comment:3 Changed 12 years ago by Simon G. <dev@…>

Triage Stage: UnreviewedDesign decision needed

Guys - can you raise this issue in django-developers? These all sound like good improvements to make, and we should see what the core developers think.

comment:4 Changed 12 years ago by Marek Kubica <pythonmailing@…>

Cc: pythonmailing@… added

I found out that ticket #4028 requests more or less what's developed here. Was there any discussion in django-developers? I'd be interessted to see it in the Django admin. Malcolm Tredinnick closed that ticket, but the newform-admin is still not merged, unfortunately.

Changed 12 years ago by Marek Kubica <pythonmailing@…>

Attachment: adminforeign.2.rev6000.diff added

The adminforeign.2.diff ported to SVN revision 6000

comment:5 Changed 12 years ago by Marek Kubica <pythonmailing@…>

Version: 0.95SVN

I tested the adminrelated.2.diff, applied it to the quite recent revision 6000 and it went more or less clean. One hunk was rejected but it turned out not to absolutely neccessary. It works well, althought I suspect that there will be crashes. But on the first look it looks promising. I am planning to port both adminrelated.2.diff which works with One-to-Many relationships and adminrelated.3.diff which works with One-to-One relationships to a current SVN revision, hopefully for inclusion in the trunk.

comment:6 Changed 12 years ago by Jacob

Triage Stage: Design decision neededSomeday/Maybe

At some point, we'll be reworking the admin interface, and this will be one of the things we examine at that time.

comment:7 Changed 9 years ago by Simon Meers

Resolution: duplicate
Status: newclosed

The admin code has changed too much since this patch was created; I suggest moving discussions to #13165 (which I guess is technically the real duplicate), which has a newer patch. We still have some admin permission issues to solve before getting the patches committed. There are some design decisions to be made regarding dynamic linking using JavaScript also. See discussions at

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