Skip to main content

Viewsets for Django using HTMX, Chartjs and DataTables

Project description

Django CI codecov Maintainability Test Coverage License: GPL v3

django-htmx-viewsets

Viewsets for Django using HTMX and DataTables

Built with

Description

When working with Django REST framework you will stumble upon so called ViewSets. They allow you to combine a set of related Views without repeating. This aproach has no counterpart in Django itself.

Therefore I created this package.

Features

  • Create a viewset with one line
  • Dynamic loading of DetailView, UpdateView, CreateView and DeleteView
  • Urls are auto created
  • Queryset group by, filter and exclude by all possible date and time transform lookups
  • Auto create mixed chart with AJAX loading
  • Auto create table with AJAX loading
  • Customizable architecture[^1]

[^1]: Things may change while in early state (<1.0.0)

Screenshot

django-htmx-viewsets_screenshot1

Quick-Start

Installation

pip install django-htmx-viewset

views.py

Create a ModelViewset by passing the model

MainViewSet = modelviewset_factory(model=Main)

or a queryset

MainViewSet = modelviewset_factory(queryset=Main.objects.all())

urls.py

app_name = 'test_db'
urlpatterns = [
    path('main/', include(MainViewSet.urls)),
]

Middleware

MIDDLEWARE += ['django_htmx.middleware.HtmxMiddleware', "debug_toolbar.middleware.DebugToolbarMiddleware",]

Template

Project contains a full template. If you want to use your own template, you can overwrite the template (htmx_viewsets/full.html) or pass the full_template_name as kwarg to modelviewset_factory. The template should contain the following tags and blocks:

{% load htmx_viewsets %}
<html>
  <head>
    {% htmx_viewsets_static_all %}
  </head>
  <body>
    <div class="container">
      {% block main %}{% endblock main %}
      {% htmx_viewsets_fixed_content %}
    </div>
  </body>
</html>

htmx_viewsets_static_all can be splitted by using htmx_viewsets_static_js and htmx_viewsets_static_css.

htmx_viewsets_fixed_content can be splitted by using htmx_viewsets_modal and htmx_viewsets_messages.

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

django-htmx-viewsets-0.0.6.tar.gz (804.6 kB view hashes)

Uploaded Source

Built Distribution

django_htmx_viewsets-0.0.6-py3-none-any.whl (809.3 kB view hashes)

Uploaded Python 3

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