Skip to main content

More Cool Django Rest Framework Stuff

Project description

:warning: Warning NonPaginatedXLSXRenderer does not work with newer versions of drf-renderer-xlsx. Please set your version of drf-renderer-xlsx to 0.3.8.

django-rest-framework-more

More Cool Django Rest Framework Stuff

install

pip3 install djangorestframework-more or pipenv install djangorestframework-more

features

NonPaginatedCSVRenderer and NonPaginatedXLSXRenderer

In case you want a CSV or XLSX (Excel) renderer that doesn't respect pagination:

# in settings.py
REST_FRAMEWORK = {
    'DEFAULT_RENDERER_CLASSES': [
        'rest_framework.renderers.JSONRenderer',
        'rest_framework.renderers.BrowsableAPIRenderer',
        'rest_framework_more.renderers.NonPaginatedCSVRenderer',
        'rest_framework_more.renderers.NonPaginatedXLSXRenderer'
    ]
}

If you'd like to learn more about using renderers in Django Rest Framework, see https://www.django-rest-framework.org/api-guide/renderers/#setting-the-renderers

Creater Model Serializer Class

# in serializers.py
from app.models import Car
from rest_framework_more.serializers import create_model_serializer_class

CarSerializer = create_model_serializer_class(model=Car)

Create Model Filter Form

# forms.py
from app.models import Car
from rest_framework_more.filters import create_model_filter_form

CarFilterForm = create_model_filter_form(model=Car)

Create Model Filter Set Class

# forms.py
from app.models import Car
from rest_framework_more.filters import create_model_filterset_class

CarFilterSet = create_model_filterset_class(model=Car)

Create Model ViewSet Class

# views.py
from app.models import Car
from rest_framework_more.viewsets import create_model_viewset_class

CarViewSet = create_model_viewset_class(model=Car)

FileNameMixin

The FileNameMixin automatically generates a more descriptive filename for CSV and Excel exports than the default "download". It first tries to convert the url path into a filename. If that doesn't succeed it tries to pull the filename from the queryset's model.

# views.py
from rest_framework_more.mixins import FileNameMixin

class CarViewSet(FileNameMixin, ReadOnlyModelViewSet):
...    

# if the CarViewSet is called from the url /api/cars it will generate a download filename of api_cars.csv

contact

If you have any issues, feel free to post an issue at https://github.com/DanielJDufour/django-rest-framework-more/issues or email the package author at daniel.j.dufour@gmail.com

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

djangorestframework-more-1.0.0.tar.gz (10.3 kB view details)

Uploaded Source

File details

Details for the file djangorestframework-more-1.0.0.tar.gz.

File metadata

  • Download URL: djangorestframework-more-1.0.0.tar.gz
  • Upload date:
  • Size: 10.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.5.0.1 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.5

File hashes

Hashes for djangorestframework-more-1.0.0.tar.gz
Algorithm Hash digest
SHA256 a9830408b9ba54759a8c5b021840a6a0a98d5a50020344f26cc1edca22d9c338
MD5 02bda5624cab755e8ad385257454c1ca
BLAKE2b-256 257eb92aec032faf69d827313faaee8646fce3bf034179561cf40b8267b224f0

See more details on using hashes here.

Provenance

Supported by

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