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 details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

Details for the file django-htmx-viewsets-0.0.6.tar.gz.

File metadata

  • Download URL: django-htmx-viewsets-0.0.6.tar.gz
  • Upload date:
  • Size: 804.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for django-htmx-viewsets-0.0.6.tar.gz
Algorithm Hash digest
SHA256 b677faea3edeead4f9100a51501c22d12393eefb526de3917c521529d1dc975e
MD5 5855053073d1fca25c594af352441290
BLAKE2b-256 4ab8a7326045e015e52629ced822430e1184ca9a48e5240ca37812d18e943641

See more details on using hashes here.

Provenance

File details

Details for the file django_htmx_viewsets-0.0.6-py3-none-any.whl.

File metadata

File hashes

Hashes for django_htmx_viewsets-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 15107b2e49805aed7e97d51986c7ba431c6dacbbe044d4c5e206df056f815fcc
MD5 b5bec3d74676b51538fda900c03d863d
BLAKE2b-256 e7ab16e034b40c4d49802f2ad24f53d371fe6519d20e7c4bb97002f4e6e05c6e

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