Login

Tag "admin-actions"

Snippet List

Ultimate(?) export/download CSV admin action

This owes a debt to a number of earlier snippets by myself and others, including: *(most directly)* [#2868](http://djangosnippets.org/snippets/2868/), plus [#2020](http://djangosnippets.org/snippets/2020/), [#2712](http://djangosnippets.org/snippets/2712/), [#1697](http://djangosnippets.org/snippets/1697/) Use of OrderedDict means it requires Python 2.7+. You also need to `pip install singledispatch` which is a backport of a Python 3.4 feature. Singledispatch (along with custom attributes instead of a factory function) gives a very clean interface in your ModelAdmin, whether or not you need a custom `short_description`. This version allows you to (optionally) specify custom column labels, or to (optionally) use Django's usual prettifying mechanism (`field.verbose_name`). Thanks to #2868 it can do relation-spanning double-underscore lookups and also model attribute/method (rather than field) lookups for columns, just like you can in your ModelAdmin `list_display`.

  • csv
  • admin-actions
Read More

More generic CSV export admin action factory

based on #2020 This one is even more generic than the previous generic ones since you can specify in fields any attribute you will give to the admin interface and not just fields from the model. You can for example directly export the list_display as a list of fields, including look-ups for related attributes that you may have defined in a function inside the Admin Class

  • admin
  • csv
  • related
  • admin-actions
Read More

Generic CSV export admin action factory with relationship spanning fields and labels

Based on [#2712](../2712/) "This snippet creates a simple generic export to csv action that you can specify the fields you want exported and the labels used in the header row for each field. It expands on #2020 by using list comprehensions instead of sets so that you also control the order of the fields as well." The additions here allow you to span foreign keys in the list of field names, and you can also reference callables.

  • admin
  • generic
  • export
  • csv
  • admin-actions
  • export-csv
Read More

Generic admin action export selected rows to excel

Based on [Snippet 2558](http://djangosnippets.org/snippets/2558/) but without saving the generated file to disk before downloading. Requires, pyExcelerator Usage: Add the code to your project, e.g. a file called actions.py in the project root. Register the action in your apps admin.py: `from myproject.actions import export_as_xls class MyAdmin(admin.ModelAdmin): actions = [export_as_xls]`

  • admin
  • export
  • admin-actions
  • xls
Read More

Database backup with admin command

Detect type of database (MySQL, PostgreSQL or SQLite) and make backup. In this moment ONLY WORK in GNU/Linux, NOT WIN.

  • database
  • admin-actions
  • backup
  • MySQL
  • admin-command
  • SQLite
  • PostgreSQL
Read More
Author: jhg
  • 1
  • 3

Generic admin action export selected rows to excel

Based on [http://djangosnippets.org/snippets/1697/](http://djangosnippets.org/snippets/1697/) but improved with multiline fields, and unicode chars. Also it generates an xls file, not a csv one. Requires, pyExcelerator *Usage:* Add the code to your project, e.g. a file called actions.py in the project root. Register the action in your apps admin.py: from myproject.actions import export_as_xls class MyAdmin(admin.ModelAdmin): actions = [export_as_xls]

  • export
  • admin-actions
  • xls
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

Redirect with change list with filters intact with admin actions

When using the django admin as a means of moderating reviews on a site, the obvious choice was to use admin actions and do everything from a single screen. The I stumbled across was that after the actions were peformed, the app redirected to the change list without any filters. This meant that filtering on un-moderated reviews was lost as soon as a change was made. It turns out that the solution is pretty simple, you just put a redirect to request.get_full_path() at the end of the admin action. I think this should be the default behaviour, but the fix is simple nonetheless.

  • admin
  • admin-actions
Read More

10 snippets posted so far.