Django form fieldset inspire django admin fieldset.
Project description
django-forms-fieldset
Django form fieldset inspire django admin fieldset
Installation ![](https://pypi-camo.freetls.fastly.net/4400adba27995523bf6dfc2f714ebe4b15b2c28e/68747470733a2f2f696d672e736869656c64732e696f2f707970692f762f646a616e676f2d666f726d732d6669656c647365742e737667)
pip install django-forms-fieldset
Usage
settings
Add forms_fieldset
to your INSTALLED_APPS setting like this:
INSTALLED_APPS = [
...
'forms_fieldset',
]
load template
{% load forms_fieldset static %}
<link rel="stylesheet" type="text/css" href="{% static 'forms_fieldset/css/main.css' %}">
<form>
{{ form|fieldset:'#42945c' }}
</form>
Note : The fieldset filter receives the color of the titles of the form groups, by default this color is used: # 79AEC8)
Complete Guide
models
from django.db import models
# Create your models here.
class Student(models.Model):
first_name = models.CharField(max_length=200, verbose_name="First Name")
last_name = models.CharField(max_length=200, verbose_name="Last Name")
email = models.EmailField(unique=True, verbose_name="Email")
adress = models.CharField(max_length=200, verbose_name="Adress")
mother_name = models.CharField(max_length=200, verbose_name="Mother Name")
father_name = models.CharField(max_length=200, verbose_name="Father Name")
class Note(models.Model):
SUBJECTS = (
('Math', 'Math'),
('French', 'French'),
('Physical', 'Physical'),
)
student = models.ForeignKey('Student', on_delete=models.CASCADE, related_name="notes")
subject = models.CharField(max_length=200, choices=SUBJECTS, verbose_name="Subject")
value = models.IntegerField(verbose_name="Notation")
class Meta:
verbose_name = "Les notes"
verbose_name_plural = "Les notes"
forms
from django.forms import ModelForm
from .models import Student
class StudentForm(ModelForm):
fieldsets = [
("Student Information", {'fields': [
('first_name', 'last_name'),
('email', 'adress'),
]}),
("Parent Information", {'fields': [
'mother_name',
'father_name',
]}),
]
class Meta:
model = Student
fields = '__all__'
views
from django.shortcuts import render
from django.forms import inlineformset_factory
from .forms import StudentForm
from .models import Student, Note
# Create your views here.
def home(request):
form = StudentForm()
InlineForm = inlineformset_factory(Student, Note,
fields=('subject', 'value',), exclude=('pk',), can_delete=False,
)
if request.method == 'POST':
form = Form(request.POST, request.FILES)
formset = InlineForm(request.POST, request.FILES)
#save...
context = {
'form': form,
'inline_form': InlineForm()
}
return render(request, 'home.html', context)
template
{% load forms_fieldset static %}
<!DOCTYPE html>
<html>
<head>
<title>Home page</title>
<link rel="stylesheet" type="text/css" href="{% static 'forms_fieldset/css/main.css' %}">
</head>
<body style="width: 75%; margin: 50px auto">
<h1>Student form information</h1>
<form>
{{ form|fieldset:'#42945c' }}
{{ form_inline|inline_fieldset:"#42945c,Note des eleves" }}
</form>
</body>
</html>
enjoy
Features
- Fieldset django form
- Fieldset (tabular style) inline form
Credit
Harouna Diallo
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-forms-fieldset-1.0.0.tar.gz
(278.4 kB
view hashes)
Built Distribution
Close
Hashes for django-forms-fieldset-1.0.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | faec6f2776e8b02c5fc7311968e7799fa468ec28636f81f6e09b1a49302bc5e1 |
|
MD5 | f37e775ffd6d98d01e34438ba990677d |
|
BLAKE2b-256 | acedaedeb35bfcdc6dfe3ca8f6ea47adafca9cd82e7219e188766b294b54e813 |
Close
Hashes for django_forms_fieldset-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 695b3ba06be8593b5bb85967c5414f25b6a8b747b3ea5057eb104965e9f3cd7d |
|
MD5 | 066e149fc87f0e05c03a3d8ac834dc46 |
|
BLAKE2b-256 | acfd1d3da7aed04f1365bd3f684c8c1b0f58baf3756e70908deb1cf8cfc9ebcc |