djangosnippets.org: Latest snippets tagged with 'admin-actions'http://djangosnippets.org/tags/admin-actions/2020-02-11T08:48:18.443166-06:00Streaming large CSV files via admin actions
2020-02-11T08:48:18.443166-06:00asta-kohttp://djangosnippets.org/snippets/10767/<p>Based on https://djangosnippets.org/snippets/2020/ and https://stackoverflow.com/questions/5146539/streaming-a-csv-file-in-django
Can be used on really large querysets.</p>
Freely redistributableGeneric CSV export admin action factory with relationship spanning fields and labels, and many to many fields
2014-02-01T19:44:04.482375-06:00selimnairbhttp://djangosnippets.org/snippets/3022/<p>Based on <a href="https://djangosnippets.org/snippets/2868/">#2868</a></p>
<p>Now with support for writing the absolute URL of file fields</p>
Freely redistributableUltimate(?) export/download CSV admin action
2013-10-02T07:23:13.270131-05:00anentropichttp://djangosnippets.org/snippets/2995/<p>This owes a debt to a number of earlier snippets by myself and others, including:
<em>(most directly)</em> <a href="http://djangosnippets.org/snippets/2868/">#2868</a>, plus <a href="http://djangosnippets.org/snippets/2020/">#2020</a>, <a href="http://djangosnippets.org/snippets/2712/">#2712</a>, <a href="http://djangosnippets.org/snippets/1697/">#1697</a></p>
<p>Use of OrderedDict means it requires Python 2.7+. You also need to <code>pip install singledispatch</code> which is a backport of a Python 3.4 feature.</p>
<p>Singledispatch …</p>
Freely redistributableMore generic CSV export admin action factory
2013-06-25T06:42:45.009856-05:00Rmatthttp://djangosnippets.org/snippets/2932/<p>based on #2020</p>
<p>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.</p>
<p>You can for example directly export the list_display as a list of fields, including …</p>
Freely redistributableGeneric CSV export admin action factory with relationship spanning fields and labels
2012-12-21T15:41:10.986777-06:00blackrobothttp://djangosnippets.org/snippets/2868/<p>Based on <a href="../2712/">#2712</a></p>
<p>"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 …</p>
Freely redistributableGeneric admin action export selected rows to excel
2012-10-19T14:14:18.546268-05:00aemb87http://djangosnippets.org/snippets/2834/<p>Based on <a href="http://djangosnippets.org/snippets/2558/">Snippet 2558</a> but without saving the generated file to disk before downloading.</p>
<p>Requires, pyExcelerator</p>
<p>Usage:</p>
<p>Add the code to your project, e.g. a file called actions.py in the project root.</p>
<p>Register the action in your apps admin.py:</p>
<p><code>from myproject.actions import export_as_xls
class MyAdmin(admin.ModelAdmin):
actions = [export_as_xls]</code></p>
Freely redistributableDatabase backup with admin command
2012-08-19T05:59:45.606089-05:00jhghttp://djangosnippets.org/snippets/2804/<p>Detect type of database (MySQL, PostgreSQL or SQLite) and make backup. In this moment ONLY WORK in GNU/Linux, NOT WIN.</p>
Freely redistributableGeneric admin action export selected rows to excel
2011-09-30T01:13:22.100118-05:00jordichttp://djangosnippets.org/snippets/2558/<p>Based on <a href="http://djangosnippets.org/snippets/1697/">http://djangosnippets.org/snippets/1697/</a>
but improved with multiline fields, and unicode chars.
Also it generates an xls file, not a csv one.</p>
<p>Requires, pyExcelerator</p>
<p><em>Usage:</em></p>
<p>Add the code to your project, e.g. a file called actions.py in the project root.</p>
<p>Register the action in your apps admin.py:</p>
<pre><code>from myproject.actions import export_as_xls …</code></pre>
Freely redistributableDynamically create Django admin actions
2009-12-14T15:14:22.776025-06:00pantsmanhttp://djangosnippets.org/snippets/1836/<p>With this snippet, I made a set of admin actions for assigning <code>Quality</code> objects to <code>Package</code> objects.</p>
<p>The Django docs for <a href="http://docs.djangoproject.com/en/1.1/ref/contrib/admin/actions/#django.contrib.admin.ModelAdmin.get_actions">ModelAdmin.get_actions</a> explain the dictionary of tuples that is returned.</p>
Freely redistributableRedirect with change list with filters intact with admin actions
2009-07-10T04:33:45.729982-05:00AndrewIngramhttp://djangosnippets.org/snippets/1621/<p>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. …</p>
Freely redistributable