Skip to main content

Django queryset Excel extraction

Project description

django-excel-extract

PyPI download month PyPI version Python versions Django Versions

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/

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:

index


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:

index


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:

index


Features

  • Export any Django model QuerySet to Excel.
  • Flexible customize fields output (dates, datetimes, booleans, choices, annotated fields).
  • Exclude specific fields.
  • Supports ManyToMany and ForeignKey fields.
  • Supports main objects query (.all(), .get(), .values(), .annotate())
  • Simple integration into Django views.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_excel_extract-0.0.8.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_excel_extract-0.0.8-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

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

Hashes for django_excel_extract-0.0.8.tar.gz
Algorithm Hash digest
SHA256 1a2472cc86e46aac9e67424959641ed0f018cc115b04c9489ddd22e73feef60b
MD5 1732e507f0860765e4ebe20d09f15dd2
BLAKE2b-256 e2b4e505b52436b8206798ea7fb9f6f452198619ca7dd1e04893e38c7e01fdc3

See more details on using hashes here.

File details

Details for the file django_excel_extract-0.0.8-py3-none-any.whl.

File metadata

File hashes

Hashes for django_excel_extract-0.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 54a6ccdf8ed470de3bd8baf94ff362f02ed694bffca2db1501503e7cf308bf5c
MD5 c1cefc5666b40270f1ce3186b0b948bc
BLAKE2b-256 744afd8f307adada48df16baa492692ea09d3af7a724bc91dc00a2b8defe1d69

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page