# django-simple-export-admin
A simple django admin allow your export queryset to xlsx file.
## Install
```shell
pip install django-simple-export-admin
```
## Usage
**pro/settings.py**
```python
INSTALLED_APPS = [
...
'django_static_fontawesome',
'django_changelist_toolbar_admin',
'django_simple_export_admin',
...
]
```
- django_static_fontawesome, django_changelist_toolbar_admin and django_simple_export_admin are required.
**app/models.py**
```python
from django.db import models
class Category(models.Model):
name = models.CharField(max_length=32)
class Book(models.Model):
name = models.CharField(max_length=32)
author = models.CharField(max_length=32)
category = models.ForeignKey(Category, on_delete=models.SET_NULL, null=True, blank=True)
is_published = models.NullBooleanField()
published_date = models.DateField(null=True)
count = models.IntegerField(default=0)
def preview(self):
return "/preview/{0}.png".format(self.pk)
preview.short_description = "Preview Image Path"
class Meta:
permissions = [
("export_filtered_books", "Export all filtered books"),
]
```
**app/admin.py**
```python
from django.contrib import admin
from django_simple_export_admin.admin import DjangoSimpleExportAdmin
from django_simple_export_admin.admin import NullBooleanRender
from django_simple_export_admin.admin import DateRender
from django_simple_export_admin.admin import Sum
from .models import Book
class BookAdmin(DjangoSimpleExportAdmin, admin.ModelAdmin):
list_display = ["name", "author"]
list_filter = ["is_published", "published_date", "author"]
django_simple_export_admin_exports = {
"filtered-books": {
"label": "Export All Filtered Books",
"icon": "fas fa-book",
"filename": "Book",
"fields": [
{"field": "forloop.counter1", "label": "Index"},
{"field": "name", "label": "Book Name", "footer-value": "Sum:"},
{"field": "count", "label": "Stock", "footer-value": lambda: Sum()},
{"field": "category__name"},
{"field": "author", "label": "Author", "empty_value": "-"},
{"field": "is_published", "label": "Is Published", "render": NullBooleanRender("UNKNOWN", "YES", "NO")},
{"field": "published_date", "label": "Published Date", "render": DateRender()},
],
"export-filtered": True,
"permissions": ["django_simple_export_admin_example.export_filtered_books"],
}
}
```
- `label` default to _("Export").
- `icon` default to None means no icon.
- `filename` default to model_name.
- `export-filtered` default to False, means always export all queryset without filtering.
- `permissions` default to None, means only super admin have permission to do exporting.
- `fields`
- `field` can be field of the model instance, callable function of the model instance, callable function of the admin which takes model instance parameter. Similar with field name in `list_display`. `field == forloop.counter1` will always display row index, e.g. 1,2,3...
- `label` is the header of the column. If missing label, field.verbose_name or function.short_description will be used firstly. If still null, use the field name.
- `render` is a callable object that transform the original value to display value.
- `empty_value` only works when `render` is not provided, it is the display value for orignal None value.
- `footer-value` is the value display at the bottom row. It can be an instance of Aggregate that accept every item value of this field and calc the final value at last. It can be a staic value.
- `start-row-index` is row index where begin to write data. starts from 1.
- `xlsx-template` template xlsx file path.
- `show-header` True or False means show header or not.
- `col` Which col the field value will be stored. Mostly it is 1-based index number. Use list<int> so that you can split long string into multiple cells. Xlsx cell size limit to 32*1024 characters.
## Shipped Renders
- django_simple_export_admin.admin.ForceStringRender
- django_simple_export_admin.admin.DateRender
- django_simple_export_admin.admin.BooleanRender
- django_simple_export_admin.admin.NullBooleanRender
## Shipped Aggregates
- django_simple_export_admin.admin.Sum
- django_simple_export_admin.admin.Average
- django_simple_export_admin.admin.Count
## Releases
### v0.1.0
- First release.
### v0.1.1
- Fix footer-value problem. If use an instance of Aggregate in settings, the instance is used globally, so that the final value if not correct. So you must add lambda to dynamically to create a new instance very time.
### v0.1.2
- Fix document.
### v0.1.3
- Fix queryset limited by list_per_page problem, reset it to MAX_ROWS=999999.
- Fix related field problem.
- Change __row_index to forloop.counter1, because __ used for related object property.
- If field label setting missing, found it's field-verbose-name or function-short-description first.
- Use get_xxx_display() for choice field.
- Add xlsx-template support.
- Add start-row-index support.
- Add show-header support.
### v0.1.4
- Fix loop.counter1 problem when start-row-index != 1.
### v0.1.5
- Fix requirements.txt in setup stage.
- Add app_requires in django_simple_export_admin.__init__.py to work with django-app-requires.
### v0.1.6
- Add long string value split into multiple cells support.
### v0.1.7
- Doc update.
### v0.1.9
- Fix ugettext problem.
### v0.1.10
- Fix urlquote problem.
Raw data
{
"_id": null,
"home_page": "",
"name": "django-simple-export-admin",
"maintainer": "Feng YingLiang",
"docs_url": null,
"requires_python": "",
"maintainer_email": "fengyingliang@zencore.cn",
"keywords": "django admin extentions,django simple export admin",
"author": "Feng YingLiang",
"author_email": "fengyingliang@zencore.cn",
"download_url": "https://files.pythonhosted.org/packages/5b/8f/3b07efb4e30f69c1a2651777c0defd1b962e1527b6d2eaa91f88e895cdbf/django-simple-export-admin-0.1.10.tar.gz",
"platform": null,
"description": "# django-simple-export-admin\n\nA simple django admin allow your export queryset to xlsx file.\n\n\n## Install\n\n```shell\npip install django-simple-export-admin\n```\n\n## Usage\n\n\n**pro/settings.py**\n\n```python\nINSTALLED_APPS = [\n ...\n 'django_static_fontawesome',\n 'django_changelist_toolbar_admin',\n 'django_simple_export_admin',\n ...\n]\n```\n\n- django_static_fontawesome, django_changelist_toolbar_admin and django_simple_export_admin are required.\n\n**app/models.py**\n\n```python\nfrom django.db import models\n\nclass Category(models.Model):\n name = models.CharField(max_length=32)\n\nclass Book(models.Model):\n name = models.CharField(max_length=32)\n author = models.CharField(max_length=32)\n category = models.ForeignKey(Category, on_delete=models.SET_NULL, null=True, blank=True)\n is_published = models.NullBooleanField()\n published_date = models.DateField(null=True)\n count = models.IntegerField(default=0)\n\n def preview(self):\n return \"/preview/{0}.png\".format(self.pk)\n preview.short_description = \"Preview Image Path\"\n\n class Meta:\n permissions = [\n (\"export_filtered_books\", \"Export all filtered books\"),\n ]\n```\n\n\n**app/admin.py**\n\n\n```python\nfrom django.contrib import admin\nfrom django_simple_export_admin.admin import DjangoSimpleExportAdmin\nfrom django_simple_export_admin.admin import NullBooleanRender\nfrom django_simple_export_admin.admin import DateRender\nfrom django_simple_export_admin.admin import Sum\nfrom .models import Book\n\nclass BookAdmin(DjangoSimpleExportAdmin, admin.ModelAdmin):\n list_display = [\"name\", \"author\"]\n list_filter = [\"is_published\", \"published_date\", \"author\"]\n\n django_simple_export_admin_exports = {\n \"filtered-books\": {\n \"label\": \"Export All Filtered Books\",\n \"icon\": \"fas fa-book\",\n \"filename\": \"Book\",\n \"fields\": [\n {\"field\": \"forloop.counter1\", \"label\": \"Index\"},\n {\"field\": \"name\", \"label\": \"Book Name\", \"footer-value\": \"Sum:\"},\n {\"field\": \"count\", \"label\": \"Stock\", \"footer-value\": lambda: Sum()},\n {\"field\": \"category__name\"},\n {\"field\": \"author\", \"label\": \"Author\", \"empty_value\": \"-\"},\n {\"field\": \"is_published\", \"label\": \"Is Published\", \"render\": NullBooleanRender(\"UNKNOWN\", \"YES\", \"NO\")},\n {\"field\": \"published_date\", \"label\": \"Published Date\", \"render\": DateRender()},\n ],\n \"export-filtered\": True,\n \"permissions\": [\"django_simple_export_admin_example.export_filtered_books\"],\n }\n }\n\n```\n\n- `label` default to _(\"Export\").\n- `icon` default to None means no icon.\n- `filename` default to model_name.\n- `export-filtered` default to False, means always export all queryset without filtering.\n- `permissions` default to None, means only super admin have permission to do exporting.\n- `fields`\n - `field` can be field of the model instance, callable function of the model instance, callable function of the admin which takes model instance parameter. Similar with field name in `list_display`. `field == forloop.counter1` will always display row index, e.g. 1,2,3...\n - `label` is the header of the column. If missing label, field.verbose_name or function.short_description will be used firstly. If still null, use the field name.\n - `render` is a callable object that transform the original value to display value.\n - `empty_value` only works when `render` is not provided, it is the display value for orignal None value.\n - `footer-value` is the value display at the bottom row. It can be an instance of Aggregate that accept every item value of this field and calc the final value at last. It can be a staic value.\n - `start-row-index` is row index where begin to write data. starts from 1.\n - `xlsx-template` template xlsx file path.\n - `show-header` True or False means show header or not.\n - `col` Which col the field value will be stored. Mostly it is 1-based index number. Use list<int> so that you can split long string into multiple cells. Xlsx cell size limit to 32*1024 characters.\n\n## Shipped Renders\n\n- django_simple_export_admin.admin.ForceStringRender\n- django_simple_export_admin.admin.DateRender\n- django_simple_export_admin.admin.BooleanRender\n- django_simple_export_admin.admin.NullBooleanRender\n\n## Shipped Aggregates\n\n- django_simple_export_admin.admin.Sum\n- django_simple_export_admin.admin.Average\n- django_simple_export_admin.admin.Count\n\n\n## Releases\n\n### v0.1.0\n\n- First release.\n\n### v0.1.1\n\n- Fix footer-value problem. If use an instance of Aggregate in settings, the instance is used globally, so that the final value if not correct. So you must add lambda to dynamically to create a new instance very time.\n\n### v0.1.2\n\n- Fix document.\n\n### v0.1.3\n\n- Fix queryset limited by list_per_page problem, reset it to MAX_ROWS=999999.\n- Fix related field problem.\n- Change __row_index to forloop.counter1, because __ used for related object property.\n- If field label setting missing, found it's field-verbose-name or function-short-description first. \n- Use get_xxx_display() for choice field.\n- Add xlsx-template support.\n- Add start-row-index support.\n- Add show-header support.\n\n### v0.1.4\n\n- Fix loop.counter1 problem when start-row-index != 1.\n\n### v0.1.5\n\n- Fix requirements.txt in setup stage.\n- Add app_requires in django_simple_export_admin.__init__.py to work with django-app-requires.\n\n### v0.1.6\n\n- Add long string value split into multiple cells support.\n\n### v0.1.7\n\n- Doc update.\n\n### v0.1.9\n\n- Fix ugettext problem.\n\n### v0.1.10\n\n- Fix urlquote problem.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A simple django admin allow your export queryset to xlsx file.",
"version": "0.1.10",
"project_urls": null,
"split_keywords": [
"django admin extentions",
"django simple export admin"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "8fdb39cbfd20c05e2ae773769481a2c1821004404b013aa3c0675c29fea7f3f8",
"md5": "f7587a9397960efb8c2ab73ee56f8053",
"sha256": "ddcc38c4c398bee2aae9b65140851ee242e135615869177663bd9cd64e84adc8"
},
"downloads": -1,
"filename": "django_simple_export_admin-0.1.10-py3-none-any.whl",
"has_sig": false,
"md5_digest": "f7587a9397960efb8c2ab73ee56f8053",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 10921,
"upload_time": "2023-09-22T02:45:44",
"upload_time_iso_8601": "2023-09-22T02:45:44.443601Z",
"url": "https://files.pythonhosted.org/packages/8f/db/39cbfd20c05e2ae773769481a2c1821004404b013aa3c0675c29fea7f3f8/django_simple_export_admin-0.1.10-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "5b8f3b07efb4e30f69c1a2651777c0defd1b962e1527b6d2eaa91f88e895cdbf",
"md5": "924f4e98fea09349e68e165a3647d8bf",
"sha256": "55a3c3040cfda01fca15f2036a5447cb0c4ae45616d6af860a7401fb91c56b08"
},
"downloads": -1,
"filename": "django-simple-export-admin-0.1.10.tar.gz",
"has_sig": false,
"md5_digest": "924f4e98fea09349e68e165a3647d8bf",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 11269,
"upload_time": "2023-09-22T02:45:46",
"upload_time_iso_8601": "2023-09-22T02:45:46.294952Z",
"url": "https://files.pythonhosted.org/packages/5b/8f/3b07efb4e30f69c1a2651777c0defd1b962e1527b6d2eaa91f88e895cdbf/django-simple-export-admin-0.1.10.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-09-22 02:45:46",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "django-simple-export-admin"
}