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.
Open source is love, and coffee is fuel. If my code helped you out, send a coffee my way ☕😉😎
Metadata
Release files for django-excel-extract 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| django_excel_extract-1.0.0.tar.gz | 6.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_excel_extract-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 13.0 kB
Release files / django_excel_extract-1.0.0.tar.gz
| Download URL | django_excel_extract-1.0.0.tar.gz |
|---|---|
| Size | 6.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
66e181be52d62e3ed3e8f7976649518e820b00c37103001ff37721a1115ac1e2
|
|
BLAKE2b-256 checksum How to use checksums |
5b856841756314194a9c41fa1ca5187407a211076b481f8dfccb1127a181afd6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.10
|
Release files / django_excel_extract-1.0.0-py3-none-any.whl
| Download URL | django_excel_extract-1.0.0-py3-none-any.whl |
|---|---|
| Size | 6.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
019588f6f4f18ae4812ff91a24ca9472eb35e53fa7e60baf2358be489e2136c2
|
|
BLAKE2b-256 checksum How to use checksums |
7fa63b9bcb98d90ccd0a373828aa31893a80cebe606c0a6854f309e80581754f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.10
|