Login

Tag "admin"

241 snippets

Snippet List

View all log entries in the admin

By default, you can only see the action log ("History") for particular model instances and a list of your own actions on the admin's index. This adds a fully-fledged admin view for the LogEntry model, where you can filter actions by user, content type, action type, browse by change date, and also search in the change message. Add the code to any of your apps' admin.py. The entries will be visible only to superusers and won't be editable.

  • admin
  • logentry
Read More

AdminPeepingMiddleware

Peeping middleware, that replaces active user to another one for current http request. Admin permissions required to activate, so you can place this snippet even on the production server. Very useful for debugging purposes. Wish it to be part of Django. How to use: Put this middleware after all other middlewares in the list. Then just add ?as_user=username or &as_user=username to the url, where username is the name of user whose views you want to see.

  • middleware
  • admin
  • view
  • permissions
  • peep
Read More

Django Collapsed Stacked Inlines

A simple jQuery javascript that collapses all stacked inline rows for better handling of large inline fieldsets. It also adds "Show"/"Hide"-buttons for showing/hiding each row, which could be customized and styled using css. **Usage (see below for example):** Include the javascript on your admin page, together with jQuery, and it'll automatically affect all stacked inlines. **Works with** Django 3.1.4 (Might work with other versions with or without adjustments, but not tested) **Use example:** *admin.py:* class DateInline(admin.StackedInline): model = Date extra = 10 class EventAdmin(admin.ModelAdmin): inlines = [DateInline] class Media: js = ['js/collapsed-stacked-inlines.js'] admin.site.register(Event, EventAdmin)

  • javascript
  • admin
  • jquery
  • inline
  • collapse
  • stacked
Read More

Smart wrapping Django admin's delete_selected

The idea here is to wrap the original `delete_selected` functionality in a way that I shouldn't have to reimplement the templates (confirmation/error response) serving, just extend the original. What this code does, it wraps the queryset's delete function with a closure, so when it really gets called (after the confirmation), it executes the extra functionality you wish to. After looking at the original code, this seemed to be the most efficient way of doing it.

  • admin
  • wrap
  • delete_selected
Read More

Get admin url for a model

Add this to your model to be able to get their admin change link from anywhere Useful if you want to jump to the admin screen of an object you are looking at on the front end

  • admin
  • url
Read More

instant 'master' admin site

The newforms-admin branch (to be merged by 0.97, I think) is very nice to work with, separating models from the admin. It is trivial to create an admin site that includes every app that is installed. Note that you also get all your docs for things like template tags, etc.

  • admin
  • newforms-admin
Read More

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

Dynamically create Django admin actions

With this snippet, I made a set of admin actions for assigning `Quality` objects to `Package` objects. The Django docs for [ModelAdmin.get_actions][1] explain the dictionary of tuples that is returned. [1]: http://docs.djangoproject.com/en/1.1/ref/contrib/admin/actions/#django.contrib.admin.ModelAdmin.get_actions

  • admin
  • admin-actions
  • closures
Read More

AvaliabilityAtDateListFilter

If your model have two dates, start and end of something, you may want to have filter which allow you to show objects which last on specific day.

  • filter
  • admin
  • changelist
  • list_filter
Read More

Overriding Third-party Admin

With the advent of newforms-admin it's now possible to override admin interfaces without having to change any code in third-party modules. This example shows how to enable a rich-text editor for `django.contrib.flatpages` without touching Django's code at all. (Actual embedding of the editor via Javascript left as an exercise for the reader – plenty of examples of that elsewhere.)

  • admin
  • newforms-admin
  • custom
  • contrib.admin
  • override
  • rich-text
Read More

Advanced Search in django admin

This is an example on how to create a custom advanced search (like the google advanced search page) in the admin app instead of the basic search field. you need to override 2 template of the admin so in your templates/admin folder copy the html files from the original admin app as follow: change_list.html: add the name of the module of the templatetag at the top where there is the load command from: {% load adminmedia admin_list i18n %} to: {% load adminmedia admin_list custom_search_form i18n %} and on line 87 (circa) you need to load our custom template tag something like: {% block search %}{% advanced_search_form cl %}{% endblock %} search_form.html: put your form inside the <form> tags with {{asf}} should be enough (I have also removed cl.value from the input text field because would be to complex to reload form values too ) probably would be better to create 2 new clean template and extend them but I'll leave that as an exercise for the reader :) many thanks to [Peter Baumgartner to get me in the right direction after his post](http://lincolnloop.com/blog/2011/jan/11/custom-filters-django-admin/) Currently ordering in the admin panel doesn't work if you find a way to get it work please write a comment

  • admin
  • advanced-search
  • model-filtering
Read More