Login

Snippets by jcushman

Snippet List

Allow foreign key attributes in list_display with '__'

This snippet provides a subclass of admin.ModelAdmin that lets you span foreign key relationships in list_display using '__'. The foreign key columns are sortable and have pretty names, and select_related() is set appropriately so you don't need queries for each line. EDITS: * Fixed error when DEBUG=False. * Broke out `getter_for_related_field` so you can override short_description manually (see example). * Added regular foreign key fields to select_related(), since this is overriding the code in ChangeList that usually does it.

  • admin
  • foreign-key
  • list_display
Read More

"Save and Continue" keyboard command for admin, with autoscroll

This snippet is helpful if you do a lot of editing on a single large admin form (for example, in a rich text field), and want to frequently save your progress. If you press control-S, or command-S on a Mac, the admin change form will save and reload, and the page will scroll back down to where you last were. This snippet relies on jquery, [jquery.cookie](http://plugins.jquery.com/project/cookie), and the [shortcut.js](http://www.openjs.com/scripts/events/keyboard_shortcuts/) keyboard library (which doesn't use jquery, but seemed more robust than the jquery keyboard plugins I saw). It uses a temporary cookie to remember where the page was scrolled to, to avoid having to override the admin behavior. Note: don't put this in templates/admin/change_form.html -- the circular import causes a Django crash. *Edit: Had forgotten to include jquery.cookie, which I was already including elsewhere.*

  • admin
  • jquery
  • save
Read More

jcushman has posted 2 snippets.