Skip to main content

Django CI codecov Maintainability Test Coverage License: GPL v3

django-htmx-viewsets

Viewsets for Django using HTMX and DataTables. Currently in early state.

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 yourself. This aproach has no counterpart in Django itself.

Therefore I created this package.

It comes to its full power in projects where you have to create basic CRUD with listing and chart for many models. Eg. you can use it for building a powerful statistics page for online shops.

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 architecture1

Demo

Live demo

Screenshot

django-htmx-viewsets_screenshot1

Quick-Start

Installation

pip install django-htmx-viewsets

views.py

Create a ModelViewset by passing the model

MainViewSet = modelviewset_factory(model=Main)

or a queryset

MainViewSet = modelviewset_factory(queryset=Main.objects.all(), permissions=[])
# Remove permissions kwarg if you want to use django default model permissions for the views.

urls.py

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

Settings

MIDDLEWARE += ['django_htmx.middleware.HtmxMiddleware']
INSTALLED_APPS += ['django_htmx', 'htmx_viewsets']

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.

Development

Sandbox

The sandbox has multiple models containing almost all oob Django fields and relations. Currently only BinaryField, FileField, FilePathField and ImageField are missing.

git clone git@github.com:snake-soft/django-htmx-viewsets.git
cd django-htmx-viewsets
virtualenv -p python3 venv
source venv/bin/activate
pip install -e .[test]
./manage.py migrate
./manage.py runserver_plus
# To create maaaany objects:
./manage.py create_objects -w

The purpose of the 'create_objects'-command is to create a huge database to analyze the behavior in scenarios with a bigger amount of data. To create a smaller db use the command like this:

./manage.py create_objects -c 100 -w
# Create 100 of every object (Main, Parent, Child, Attribute and AttributeValues).
# w is needed when using custom parameters to confirm writing to db.

Status

This project is currently under heavy development but the main architecture is finished. All described interfaces (-> Quick-Start) will be kept but there may be changes under the hood.

Versioning

We use semver.

  • Major: Huge steps to make incompatible changes that change the documented behaviour
  • Minor: Changes in undocumented functionalities
  • Micro: Patches to fix smaller problems without changing interfaces

Code Style

  • PEP-8
  • Default line length of 80 chars

Contribution

Feel free to create a pull request. If you find any errors, please create an issue here with all neccessary details.

  1. Things may change while in early state (<1.0.0) ↩

Release files for django-htmx-viewsets 0.0.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-htmx-viewsets 0.0.9
File Size Uploaded
django-htmx-viewsets-0.0.9.tar.gz 806.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-htmx-viewsets 0.0.9
File Interpreter ABI Platform
django_htmx_viewsets-0.0.9-py3-none-any.whl Python 3 none any Details

Total release size: 1.6 MB

Release files / django-htmx-viewsets-0.0.9.tar.gz

Download URL django-htmx-viewsets-0.0.9.tar.gz
Size 806.1 kB
Tags Source
SHA-256 checksum
How to use checksums
44560c7a5aa090c64b684c03e85da996405e77c7bcc4876cb31ef243184b3177
BLAKE2b-256 checksum
How to use checksums
726953ca8e351fd075636a38195ba1eb46e14b2b8f88764e0e583a6380c5939e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Release files / django_htmx_viewsets-0.0.9-py3-none-any.whl

Download URL django_htmx_viewsets-0.0.9-py3-none-any.whl
Size 810.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
67474eb93dd16c12f1c16074e0860364bd6d2112e43b858ea93267affb90f55c
BLAKE2b-256 checksum
How to use checksums
53c249020f411015ccfd6a4954ebf5fed3b833da2a6ff65ccd4d316fea5057e1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Release history Release notifications | RSS feed

This release

0.0.9 This release

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

0.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page