Skip to main content

Generic views for Model View Serializer (MVS) pattern

Project description

Django Generic Ellis Views

Django Generic Ellis Views provides generic views for Create, Retrieve, Update, and Delete operations, requiring only the definition of serializer, model, and authorization methods.

Table of Contents

  • Quick Start
  • Usage Example
  • Features
  • Contributing
  • License

Quick Start

  1. Add 'ellis_django_views' to your INSTALLED_APPS in settings.py:

    # django-project/settings.py
    
    INSTALLED_APPS = [
        'ellis_django_views',
    ]
    
  2. Include test URLs for testing purposes in your project's urls.py:

    # django-project/urls.py
    
    from django.urls import path, include
    from ellis_django_views.tests import urls as TestUrls
    from ellis_django_views.utils import url_paths as test_url_paths
    
    urlpatterns = [
        path(test_url_paths.TEST, include(TestUrls)),
    ]
    
  3. Run migrations:

    python manage.py makemigrations
    python manage.py migrate
    
  4. Run tests:

    python manage.py test ellis_django_views
    

Usage Example

  1. Import CRUD views from 'ellis_django_views.views_implementation' and your own models and serializers:

    # django-project/django-app/views.py
    from DjangoApp.models import YourModel
    from DjangoApp.serializers import YourSerializer
    from ellis_django_views.views_implementation import (
        CreateViewImpl,
        RequestViewImpl,
        UpdateViewImpl,
        DeleteViewImpl
    )
    
  2. Create an is_authorised function which retrieves 'HTTP_AUTHORIZATION' from request headers:

    def is_authorised(self, auth_token):
        "Placeholder for authorization"
        return True
    
  3. Create CRUD views with imported 'ellis_django_views.views_implementation' views and your is_authorised function:

    # django-project/django-app/views.py
    class CreateView(CreateViewImpl):
        serializer_model = YourSerializer
        is_authorised = is_authorised
    
    class RequestView(RequestViewImpl):
        model = YourModel
        serializer_model = YourSerializer
        is_authorised = is_authorised
    
    class UpdateView(UpdateViewImpl):
        model = YourModel
        serializer_model = YourSerializer
        is_authorised = is_authorised
    
    class DeleteView(DeleteViewImpl):
        model = YourModel
        is_authorised = is_authorised
    
  4. Add the CRUD views to your urls.py:

    # django-project/django-app/urls.py
    from django.urls import path
    from DjangoApp.views import CreateView, RequestView, UpdateView, DeleteView
    
    urlpatterns = [
        path('post/', CreateView.as_view(), name='create'),
        path('get/', RequestView.as_view(), name='get'),
        path('put/', UpdateView.as_view(), name='put'),
        path('delete/', DeleteView.as_view(), name='delete'),
    ]
    

Features

  • Simplified CRUD Operations: Easily create, retrieve, update, and delete views with minimal setup.
  • Authorization Support: Implement custom authorization logic.
  • Serializer Integration: Define serializers for your models to handle validation and representation.
  • Test URLs: Built-in support for testing your views.

Contributing

If you have any suggestions or would like to contribute, please get in contact with Carl Ellis.

License

This project is licensed under the GNU General Public License Version 3 - see the LICENSE file for details.

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

ellis_django_views-0.224.tar.gz (21.1 kB view details)

Uploaded Source

Built Distribution

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

ellis_django_views-0.224-py3-none-any.whl (23.3 kB view details)

Uploaded Python 3

File details

Details for the file ellis_django_views-0.224.tar.gz.

File metadata

  • Download URL: ellis_django_views-0.224.tar.gz
  • Upload date:
  • Size: 21.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.9.6

File hashes

Hashes for ellis_django_views-0.224.tar.gz
Algorithm Hash digest
SHA256 8a8c38c541bfa09c86baea8b505fdca0bb60cbfb2abf8a8352be8e11707bd470
MD5 e158b863dc1f20482f668872bc59e4e1
BLAKE2b-256 ad36225f795377b54cda63555e0cb9dcb91fb350c08547d952962881fe92d908

See more details on using hashes here.

File details

Details for the file ellis_django_views-0.224-py3-none-any.whl.

File metadata

File hashes

Hashes for ellis_django_views-0.224-py3-none-any.whl
Algorithm Hash digest
SHA256 539252efdb1ae777bceab2bbe585d154b5bd33c6c3213f3720197ed693133431
MD5 360d10f7a24f1b1868b74f00a0616405
BLAKE2b-256 d3ef82a5912ab85d512438fa9b14d00e8e2e3493099b0f384e6c883a1790e828

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