Django queryset Excel extraction
Project description
django-excel-extract
django-excel-extract helps you easily export Django model data into an Excel file (.xlsx) with minimal setup.
Installation
pip install django-excel-extract
ORM
Avaliable ORM methods:
.all().get().filter().values().annotate()
Example
Follow the link to view main page: http://127.0.0.1:8000/app/index/
Extract Report Get button contains:
def extract_excel_get(request):
queryset = Report.objects.get(id=1)
exclude = ['id']
excel = Excel(
model=Report,
queryset=queryset,
file_name='report_get',
title='Report',
exclude=exclude,
date_time_format='%d/%m/%Y',
)
return excel.to_excel()
Result:
Extract Report Filter button contains:
def extract_excel_filter(request):
queryset = Report.objects.filter(priority=Priority.HIGH)
exclude = ['id']
excel = Excel(
model=Report,
queryset=queryset,
file_name='report_filter',
title='Report',
exclude=exclude,
date_time_format='%d/%m/%Y',
)
return excel.to_excel()
Result:
Extract Report Values button contains:
def extract_excel_values(request):
queryset = Report.objects.annotate(
days_passed=ExpressionWrapper(
now() - F('created_at'),
output_field=fields.DurationField(),
)
).values(
'id',
'report_num',
'status_report',
'type_report',
'priority',
'days_passed',
)
aggregation_field_names = {'days_passed': 'Days Passed'}
exclude = ['id']
excel = Excel(
model=Report,
queryset=queryset,
file_name='report_values',
title='Report',
exclude=exclude,
date_time_format='%d/%m/%Y',
annotation_fields_map=aggregation_field_names,
)
return excel.to_excel()
Result:
Features
- Export any Django model
QuerySetto Excel. - Flexible customize fields output
(dates, datetimes, booleans, choices, annotated fields). - Exclude specific fields.
- Supports
ManyToManyandForeignKeyfields. - Supports main objects query (
.all(),.get(),.values(),.annotate()) - Simple integration into Django views.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_excel_extract-0.0.8.tar.gz.
File metadata
- Download URL: django_excel_extract-0.0.8.tar.gz
- Upload date:
- Size: 5.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1a2472cc86e46aac9e67424959641ed0f018cc115b04c9489ddd22e73feef60b
|
|
| MD5 |
1732e507f0860765e4ebe20d09f15dd2
|
|
| BLAKE2b-256 |
e2b4e505b52436b8206798ea7fb9f6f452198619ca7dd1e04893e38c7e01fdc3
|
File details
Details for the file django_excel_extract-0.0.8-py3-none-any.whl.
File metadata
- Download URL: django_excel_extract-0.0.8-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
54a6ccdf8ed470de3bd8baf94ff362f02ed694bffca2db1501503e7cf308bf5c
|
|
| MD5 |
c1cefc5666b40270f1ce3186b0b948bc
|
|
| BLAKE2b-256 |
744afd8f307adada48df16baa492692ea09d3af7a724bc91dc00a2b8defe1d69
|