Snippet List
This snippets is inspired from [#2995](https://djangosnippets.org/snippets/2995/) but add the following:
* get rid of `singledispatch` so we can use it with python2 without pip installing anything
* streaming capabilities
* the configuration params (header, fields, exclude...) are passed to the action function so we don't pollute the ModelAdmin class
* fix utf8 issue in header
- admin
- export
- csv
- action
- stream
- export-csv
Save the snippet as actions.py within your core app, and then add an action on any model you want in it's ModelAdmin definition.
Example usage:
`from actions import export_as_csv_action`
`class YourModelAdmin(admin.ModelAdmin):`
` list_display = ('field', 'get_field2')`
` actions = [export_to_csv(filename='your-model')]`
` def get_field2(self, obj):`
` return obj.field2`
- admin
- unicode
- export
- csv
- action
Based on [#2369](https://djangosnippets.org/snippets/2369/)
Save the snippet as actions.py within your django app, and then add an action on any model you want in it's ModelAdmin definition.
Example usage:
from actions import export_as_csv_action
class YourModelAdmin(admin.ModelAdmin):
list_display = (...)
list_filter = [...]
actions = [export_as_csv_action("CSV Export", fields=[...])]
- Unicode fix (requires unidecode)
Based on [#2020](/snippets/2020/)
Save the snippet as actions.py within your django app, and then add an action on any model you want in it's ModelAdmin definition.
Example usage:
from actions import export_as_csv_action
class YourModelAdmin(admin.ModelAdmin):
list_display = (...)
list_filter = [...]
actions = [export_as_csv_action("CSV Export", fields=[...])]
* - Added UTF-8 encoding support
* - Bugs fixed
A generic admin action to export selected objects as csv file. The csv file contains a first line with header information build from the models field names followed by the actual data rows.
Access is limited to staff users.
Requires django-1.1.
**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_csv
class MyAdmin(admin.ModelAdmin):
actions = [export_as_csv]
- admin
- generic
- export
- csv
- action
This decorator handle a extra "action" parameter from an url and call this desired action in the provided views module.
Example:
from posts import views
urlpatterns = patterns('posts.views',
...
url(r'^(?P<id>\d+)/(?P<action>delete|publish|edit)/$', action(views), name="posts-action"),
...
)
In templates:
{% url posts-action id=post.id,action="delete" %}
- rest
- url
- decorator
- action
- crud
7 snippets posted so far.