Django Excel ViewSet
Small improvement in the functionality of drf for exporting data into excel file.
Examples
# models.py
from django.db.models import Model
class Contact(Model):
first_name = models.CharField( max_length=50)
last_name = models.CharField(max_length=50)
middle_name = models.CharField(max_length=50, blank=True)
email = models.EmailField(blank=True, null=True)
phone = models.CharField(max_length=15)
class Meta:
verbose_name = 'contact'
verbose_name_plural = 'contacts'
# serializers.py
from rest_framework.serializers import ModelSerializer
from django_excel_viewset.serializers import ExcelSerializerMixin
from .models import Contact
class ContactExcelSerializer(ExcelSerializerMixin, ModelSerializer):
# Settings excel table
excel_filename = "users"
excel_sheetname = "users"
excel_table_label = "Users"
datetime_cell_format = {"num_format": "dd.mm.yyyy h:mm;@", "border": 1, "border_color": "#000000"}
date_cell_format = {"num_format": "dd.mm.yyyy", "border": 1, "border_color": "#000000"}
percent_cell_format = {"num_format": "0.00"%"", "border": 1, "border_color": "#000000"}
format_cell_border = {"border": 1, "border_color": "#000000", "text_wrap": True}
format_header_table = {"bold": True, "align": "center", "border": 1, "border_color": "#000000", "text_wrap": True}
table_label_format = {"italic": True, "font_size": 14}
class Meta:
model = Contact
fields = (
"id",
"last_name",
"first_name",
"middle_name",
"phone",
"email",
)
extra_kwargs = {
"last_name": {"help_text": "Last name"},
"first_name": {"help_text": "First name"},
"middle_name": {"help_text": "Middle name"},
"phone": {"help_text": "Phone number"},
"email": {"help_text": "Email"},
}
# views.py
from django_excel_viewset.views import ExcelMixin
from rest_framework.viewsets import GenericViewSet
from .serializers import ContactExcelSerializer
from .models import Contact
class ContactViewSet(ExcelMixin, GenericViewSet):
queryset = Contact.objects.all()
serializer_class = ContactExcelSerializer
Environment variables
DJANGO_EXCEL_VIEWSET_LOCAL_TIMEZONE - setting time zone (default value "Europe/Moscow").
Required
- python >=3.11, <4.0
- django >=4.2, <6.0
- djangorestframework >=3.11
- pillow >=9.2
- xlsxwriter >=1.3.6
- pytz >=2020.1
- environs >=9.3.1
Installation
pip install django-excel-viewset
Contribution
You can run tests with pytest.
pip install poetry
poetry install
pytest
Metadata
Release files for django-excel-viewset 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django_excel_viewset-0.0.1.tar.gz | 11.6 kB | Without provenance | Details for django_excel_viewset-0.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_excel_viewset-0.0.1-py3-none-any.whl | Python 3 | none | any | Details for django_excel_viewset-0.0.1-py3-none-any.whl |
Total release size: 24.7 kB
Release files / django_excel_viewset-0.0.1.tar.gz
| Download URL | django_excel_viewset-0.0.1.tar.gz |
|---|---|
| Size | 11.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
53bc651bbbf4111fd399a6c4098dfb327069737e5267657c3738957e51f30e9b
|
|
BLAKE2b-256 checksum How to use checksums |
4629c2868e37d493b306b1ca3615c09c4443870801c61271573f8e75f68dde8d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.3 CPython/3.12.3 Linux/6.11.0-1015-azure
|
Release files / django_excel_viewset-0.0.1-py3-none-any.whl
| Download URL | django_excel_viewset-0.0.1-py3-none-any.whl |
|---|---|
| Size | 13.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8171491b8be522b8fc0dcf038060087bf2a225acbd2e8c6a4ca81cd29fba3c3d
|
|
BLAKE2b-256 checksum How to use checksums |
321a3b5d9efd7510730558c9aab595dff6fbe0e9a7666e995778ce60d2bef2b9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.3 CPython/3.12.3 Linux/6.11.0-1015-azure
|
Security for django-excel-viewset 0.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.