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.231.tar.gz (21.2 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.231-py3-none-any.whl (23.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ellis_django_views-0.231.tar.gz
  • Upload date:
  • Size: 21.2 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.231.tar.gz
Algorithm Hash digest
SHA256 ae89834b21ce0fcf9bdd6bf320d3c8a94f1a0833bb04cfe39b277d1f5017b8db
MD5 88f54e585b5125e710b9c09455b31787
BLAKE2b-256 086397f147c9edb8f8714b2825888eb9ab38165a2306707aece98efaab62551c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ellis_django_views-0.231-py3-none-any.whl
Algorithm Hash digest
SHA256 083c5587514108d339b3d2160bb3b5bc4f02899242d9105386444642581460ed
MD5 b527fc8bbd60ab434ab66a3eec28b31b
BLAKE2b-256 78bb8501f9cfc17cb6f21ee6ba5eb0ec9657bdc13c1a836fbdb0a14dd77b23dd

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