Skip to content
This repository was archived by the owner on Mar 12, 2020. It is now read-only.

birdsarah/django-spreadsheetresponsemixin

Repository files navigation

DEPRECATION NOTICE

This project is deprecated in favour of django-tables2 export functionality


View mixin for django, that generates a csv or excel sheet.

Build Status on Travis

Installation

pip install django-spreadsheetresponsemixin

Usage

Add to your django view as a mixin::

class ExcelExportView(SpreadsheetResponseMixin, ListView):
    def get(self, request):
        self.queryset = self.get_queryset()
        return self.render_excel_response()


class CsvExportView(SpreadsheetResponseMixin, ListView):
    def get(self, request):
        self.queryset = self.get_queryset()
        return self.render_csv_response()

Note you must specify a Queryset, ValuesQueryset or ValuesListQueryset on the class or pass it in when you call the render method.

You can also specify the fields and the headers as tuples if you want to refine the results and / or provide custom headers for your columns.

Exported file will be named export.csv or export.xlsx by default, but you can change this by either specifying export_filename attribute to name exported file or export_filename_root to specify only the root part of it (and let app take care of the appropriate extension).

About

View mixin for django, that generates a csv or excel sheet.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 5

Languages