Easy Contextual Admin Edit Links for Django
Something I like to include for my clients is per content/page edit links. Django doesn’t have it built in, but its not hard to add. This is a simple tutorial to get you started.
In the screenshot above, I have the edit link for an Article single in context on the page. This allows site administrators to easily update content without hunting through the administration panels.
Step 1: Where to put it?
In django 1.4.x and django 1.5.x, I make these edits to the project’s app directory’s __init__.py file.
Step 2: Add the code
Essentially, this is going to monkey patch
django.db.models.Model to have a instance method
Step 3: Show the edit link conditionally based if staff member
But wait… that staff member may not have permission for that particular resource?
This is a relevant concern. However, the django admin will sort out permissions on its own. If a staff member doesn’t have specific permissions - the link won’t take them to the update page. I’ve chosen to keep the template integration as easy as possible.
Note: you could do the permission check for the individual model resource you are trying to edit, but then these “quick” edit links become a pain to implement in the templates / less generic.