Django reusable app to simplify form construction
Project description
https://github.com/idlesign/django-siteforms
Description
Django reusable app to simplify form construction
For those who consider maintaining templates-based forms solutions for Django a burden.
Features:
Full form rendering support, including prolog and submit button
Subforms support (represent entire other form as a form field): JSON, Foreign Key, Many-to-Many
Field groups
Declarative attributes for elements
Simplified declarative forms layout, allowing fields ordering
Simple ways to make fields hidden, disabled, readonly
Aria-friendly (Accessible Rich Internet Applications)
Complex widgets (e.g. using values from multiple fields) support
Supported styling:
No CSS
Bootstrap 4
Usage
To render a form in templates just address a variable, e.g. <div>{{ form }}</div>.
Basic
Let’s show how to build a simple form.
from django.shortcuts import render
from siteforms.composers.bootstrap4 import Bootstrap4
from siteforms.toolbox import ModelForm
class MyForm(ModelForm):
"""This form will show us how siteforms works."""
disabled_fields = {'somefield'} # Declarative way of disabling fields.
hidden_fields = {'otherfield'} # Declarative way of hiding fields.
readonly_fields = {'anotherfield'} # Declarative way of making fields readonly.
class Composer(Bootstrap4):
"""This will instruct siteforms to compose this
form using Bootstrap 4 styling.
"""
class Meta:
model = MyModel # Suppose you have a model class already.
fields = '__all__'
def my_view(request):
# Initialize form using data from POST.
my_form = MyForm(request=request, src='POST')
is_valid = form.is_valid()
return render(request, 'mytemplate.html', {'form': my_form})
Composer options
Now let’s see how to tune our form.
from siteforms.composers.bootstrap4 import Bootstrap4, FORM, ALL_FIELDS
class Composer(Bootstrap4):
opt_size='sm' # Bootstrap 4 has sizes, so let's make our form small.
# Element (fields, groups, form, etc.) attributes are ruled by `attrs`.
# Let's add rows=2 to our `contents` model field.
attrs={'contents': {'rows': 2}}
# To group fields into named groups describe them in `groups`.
groups={
'basic': 'Basic attributes',
'other': 'Other fields',
}
# We apply custom layout to our form.
layout = {
FORM: {
'basic': [ # First we place `basic` group.
# The following three fields are in the same row -
# two fields in the right column are stacked.
['title', ['date_created',
'date_updated']],
'contents', # This one field goes into a separate row.
],
# We place all the rest fields into `other` group.
'other': ALL_FIELDS,
}
}
Documentation
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file django-siteforms-0.9.0.tar.gz
.
File metadata
- Download URL: django-siteforms-0.9.0.tar.gz
- Upload date:
- Size: 33.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: Python-urllib/2.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3637137ec2852775d55102e41736a8f58dbe1af40a23ee05836b08b8b603d8b8 |
|
MD5 | a31467dd0e3539445610577aaf567703 |
|
BLAKE2b-256 | 0ab7efa256b3288ab5d21e7b801a1550fcf4dede9cdb8e6c556308007460d8b2 |
File details
Details for the file django_siteforms-0.9.0-py2.py3-none-any.whl
.
File metadata
- Download URL: django_siteforms-0.9.0-py2.py3-none-any.whl
- Upload date:
- Size: 35.0 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: Python-urllib/2.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ef5e57c5e0ac5b1b6ebaa7a515e2798dbd6b4249bf94976d17e9c465cf64b3a1 |
|
MD5 | a7470a7567edcd6739832157b795132e |
|
BLAKE2b-256 | 6f493159c937e50bf70ae1db2c7df0e727a01402df6465934196b49a503d91c7 |