Skip to main content

Modernized form utilities for Django 3.2–5.2+

Project description

django-modern-form-utils is a modernized fork of the deprecated django-form-utils package, updated to support Django 4.x and 5.x, and compatible with Python 3.8+.

This package provides reusable form enhancements and rendering utilities designed for modern Django projects.

Features

  1. BetterForm and BetterModelForm: - Organize form fields into fieldsets for improved layout. - Attach row-level attributes (e.g. class, style) to each field.

  2. Template Filters for Forms: - label — Custom label rendering. - value_text, selected_values — Display selected choices as text. - optional, is_checkbox, is_multiple, is_select, is_radio — Field-type-aware rendering helpers.

  3. ClearableFileField / ClearableImageField: - Show a checkbox to clear file/image fields at form level. - Works out-of-the-box with Django Admin via ClearableFileFieldsAdmin.

  4. ImageWidget: - Shows thumbnails for image fields (supports sorl-thumbnail or easy-thumbnails).

  5. AutoResizeTextarea Widget: - Automatically resizes <textarea> based on input. - jQuery-based enhancement.

Installation

pip install django-modern-form-utils

Then, add it to your INSTALLED_APPS:

INSTALLED_APPS = [
    ...
    "modern_form_utils",
]

If you want to override the default templates, provide your own versions in: templates/modern_form_utils/better_form.html and form.html.

Usage

BetterForm Example

from modern_form_utils.forms import BetterForm

class MyForm(BetterForm):
    one = forms.CharField()
    two = forms.CharField()
    three = forms.CharField()

    class Meta:
        fieldsets = [
            ("main", {"fields": ["two"], "legend": ""}),
            ("Advanced", {
                "fields": ["three", "one"],
                "description": "Advanced fields",
                "classes": ["advanced", "collapse"]
            }),
        ]
        row_attrs = {
            "one": {"style": "display: none"}
        }

ClearableFileField Example

from modern_form_utils.fields import ClearableFileField

class MyModelForm(forms.ModelForm):
    resume = ClearableFileField()

ImageWidget Example

from modern_form_utils.widgets import ImageWidget

class MyForm(forms.ModelForm):
    avatar = forms.ImageField(widget=ImageWidget())

AutoResizeTextarea Example

from modern_form_utils.widgets import AutoResizeTextarea

class MyForm(forms.Form):
    description = forms.CharField(widget=AutoResizeTextarea())

Template Filters

Load the template filters:

{% load modern_form_utils %}

Then use in templates:

{{ form|render }}
{{ form.fieldname|label:"Custom Label" }}
{{ form.fieldname|value_text }}
{% if form.fieldname|is_checkbox %}...{% endif %}

Admin Integration

To make file fields in Django admin clearable:

from modern_form_utils.admin import ClearableFileFieldsAdmin

class MyAdmin(ClearableFileFieldsAdmin):
    pass

To use ImageWidget in admin:

class MyAdmin(admin.ModelAdmin):
    formfield_overrides = {
        models.ImageField: {"widget": ImageWidget},
    }

Settings

JQUERY_URL

JQUERY_URL = "https://code.jquery.com/jquery-3.6.0.min.js"

If unset, defaults to:

https://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js

Contributing

  • Fork this repo

  • Make sure tests pass via python runtests.py

  • Supports Django 3.2, 4.2, 5.0+ on Python 3.8–3.12

Credits

Original author: Carl Meyer (django-form-utils)

This package: Updated and maintained by Muhammad Ziauldin

GitHub: https://github.com/ziauldin123

Organization: https://github.com/Nexgsol

Package: django-modern-form-utils

License

BSD License (same as the original)

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_modern_form_utils-2.0.1.tar.gz (23.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_modern_form_utils-2.0.1-py3-none-any.whl (15.0 kB view details)

Uploaded Python 3

File details

Details for the file django_modern_form_utils-2.0.1.tar.gz.

File metadata

  • Download URL: django_modern_form_utils-2.0.1.tar.gz
  • Upload date:
  • Size: 23.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for django_modern_form_utils-2.0.1.tar.gz
Algorithm Hash digest
SHA256 2fea53f3dd23b0aea81d097b5045c33cfe49d8099babba18fcbe1cc8e7fe51b3
MD5 bf9060c2928581ad4bd0a3264aba571d
BLAKE2b-256 b59899d840016e8c6d334013959d71d9b689b91afb14adaf78c944b4734abd8d

See more details on using hashes here.

File details

Details for the file django_modern_form_utils-2.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for django_modern_form_utils-2.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 85d920721efd02e351bf52ac7d0fab36b4b01a7496a25827950c8601e8544451
MD5 14ab23593d17bfaee69482758fd7e430
BLAKE2b-256 b5e0061e5dc878bd6e436e95ffa6b872d404d698c53ff487e7ef6f849255edfc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page