radiac / django-fastview

Build admin-style views with minimal code
Other
20 stars 1 forks source link

=============== Django Fastview

Fast development of complex CRUD views for Django.

.. image:: https://github.com/radiac/django-fastview/actions/workflows/ci.yml/badge.svg :target: https://github.com/radiac/django-fastview/actions/workflows/ci.yml

.. image:: https://codecov.io/gh/radiac/django-fastview/branch/develop/graph/badge.svg?token=5VZNPABZ7E :target: https://codecov.io/gh/radiac/django-fastview

.. image:: https://readthedocs.org/projects/django-fastview/badge/?version=latest :target: https://django-fastview.readthedocs.io/en/latest/?badge=latest :alt: Documentation Status

Fastview slashes development time for modern hybrid apps - build comprehensive and completely customisable CRUD views in a couple of lines, with flexible access control, default templates, and built-in HTMX support:

.. code-block:: python

from fastview.viewgroups import ModelViewGroup
from fastview.permissions import Owner, Staff

class ContactViewGroup(ModelViewGroup):
    model = Contact
    fields = ["name", "category", "email", "phone", "last_updated"]
    search_fields = ["name"]
    filters = ["category", "last_updated"]
    permission = Owner('owner') | Staff()

# urls.py
urlpatterns = [
    ...
    url(r'^contacts/', WikiViewGroup().include(namespace="contacts")),
]

Inspired by Django's admin, you now have a group of 5 views using your own templates, ready to customise and extend. See the examples for more details.

Fastview lets you:

Note: this is an alpha release; see the roadmap <https://django-fastview.readthedocs.io/en/latest/contributing.html#roadmap> for planned breaking changes, and the upgrade notes <https://django-fastview.readthedocs.io/en/latest/upgrading.html> for instructions when upgrading.

Example

Lets write a wiki where anyone can view, add, edit and delete pages:

.. code-block:: python

# urls.py (for example purposes - normally define the viewgroup in app/views.py)
from fastview.viewgroups import ModelViewGroup
from fastview.permissions import Public
from mywiki.models import Wiki

class WikiViewGroup(ModelViewGroup):
    model = Wiki
    permission = Public()

urlpatterns = [
    url(r'^wiki/', WikiViewGroup().include(namespace="wiki")),
]

This will create a functioning set of list, detail, create, update and delete views under the /wiki/ path on your site.

There are all sorts of things you can do from here:

See the Tutorial__ in the documentation for more details.

__ https://django-fastview.readthedocs.io/en/latest/tutorial/index.html

Quickstart

  1. Install using pip::

    pip install django-fastview

  2. Add to INSTALLED_APPS::

    INSTALLED_APPS = [ ... "fastview", ]

  3. Optional: add the default JavaScript and CSS to your templates or frontend build process.

See Getting Started__ in the documentation for more details.

__ https://django-fastview.readthedocs.io/en/latest/get_started.html

Advanced example

Build a more complex view group with custom view classes and complex access controls:

.. code-block:: python

# urls.py (for example purposes)
from fastview.viewgroups import ModelViewGroup
from fastview.permissions import Public, Login, Staff, Owner, Django
from myblog.models import Blog
from myblog.views import BlogUpdateView, BlogPublishView

class BlogViewGroup(ModelViewGroup):
    model = Blog

    # Default permission for views - any views without explicit permissions will
    # require that user is logged in
    permission = Login()

    # Make the list view public by reconfiguring it with a call to View.config()
    list_view = fastview.views.generics.ListView.config(
        permission=Public(),
    )

    # Make the detail view public by reconfiguring it with the dict shorthand format
    detail_view = dict(
        permission=Public(),
    )

    # Override change with a custom view, and limit access to staff or post owners
    change_view = BlogUpdateView.config(
        permission=Staff() | Owner("owner"),
    )

    # Use the Django permission framework to manage who can delete Blog objects
    delete_view = dict(
        permission=Django("delete"),
    )

    # Add a publish view where only staff can access, but only if it's not their own
    publish_view = BlogPublishView.config(
        permission=Staff() & ~Owner("owner"),
    )

urlpatterns = [
    url(r'^blog/', BlogViewGroup().include(namespace="blog")),
]

You may then want to create a custom templates at templates/myblog/blog/list.html and templates/myblog/blog/detail.html to change the way blog posts are rendered.

For more details see the main documentation__.

__ https://django-fastview.readthedocs.io/

More examples

See Examples in the documentation for more details on these two examples, as well as how you can use fastview to: