Package: django-htmx-viewsets
django-htmx-viewsetsViewsets for Django using HTMX and DataTables.
Currently in early state.Built withhtmxchart.jsjQueryBootstrap 5DatatablesSelect2Font AwesomeDescriptionWhen 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.FeaturesCreate a viewset with one lineDynamic loading of DetailView, UpdateView, CreateView and DeleteViewUrls are auto createdQueryset group by, filter and exclude by all possible date and time transform lookupsAuto create mixed chart with AJAX loadingAuto create table with AJAX loadingCustomizable architecture[^1][^1]: Things may change while in early state (<1.0.0)DemoLive demoScreenshotQuick-StartInstallationpip install django-htmx-viewsetsviews.pyCreate a ModelViewset by passing the modelMainViewSet=modelviewset_factory(model=Main)or a querysetMainViewSet=modelviewset_factory(queryset=Main.objects.all(),permissions=[])# Remove permissions kwarg if you want to use django default model permissions for the views.urls.pyurlpatterns=[path('main/',include(MainViewSet.urls)),]SettingsMIDDLEWARE+=['django_htmx.middleware.HtmxMiddleware']INSTALLED_APPS+=['django_htmx','htmx_viewsets']TemplateProject 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><divclass="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.DevelopmentSandboxThe 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 -wThe 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.StatusThis 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.VersioningWe usesemver.Major: Huge steps to make incompatible changes that change the documented behaviourMinor: Changes in undocumented functionalitiesMicro: Patches to fix smaller problems without changing interfacesCode StylePEP-8Default line length of 80 charsContributionFeel free to create apull request.
If you find any errors, pleasecreate an issue herewith all neccessary details.