Skip to main content

django-forms-fieldset

Django form fieldset inspire django admin fieldset

Installation

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>
	{% fieldset form fieldsets '#42945c' %}
</form>

Note : The first argument of fieldset tag is the form the second the list fieldsets where you have defined the positioning of your different elements and the last the color of the title of the fieldset (by default this value is at #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,
		'fieldsets': form.fieldsets,
		'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>
		{% fieldset form fieldsets '#42945c' %}
		{% inline_fieldset inline_form '#42945c' "Note des eleves" %}
	</form>
</body>
</html>

enjoy Screenshot

Features

  1. Fieldset django form
  2. Fieldset (tabular style) inline form

Credit

Harouna Diallo

Metadata

Release files for django-forms-fieldset 0.1.2

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-forms-fieldset 0.1.2
File Size Uploaded
django-forms-fieldset-0.1.2.tar.gz 276.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-forms-fieldset 0.1.2
File Interpreter ABI Platform
django_forms_fieldset-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 554.5 kB

Release files / django-forms-fieldset-0.1.2.tar.gz

Download URL django-forms-fieldset-0.1.2.tar.gz
Size 276.9 kB
Tags Source
SHA-256 checksum
How to use checksums
c2ee5d1d0aa522800362e39874152d946a95bcc1999f524bb93af7299c0117aa
BLAKE2b-256 checksum
How to use checksums
95d40f6ee9a083953a528f1e3a7d9fc31b7e61edda70be928b78ae7280e63fa7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.5

Release files / django_forms_fieldset-0.1.2-py3-none-any.whl

Download URL django_forms_fieldset-0.1.2-py3-none-any.whl
Size 277.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d6123c6616b27313baaaf7fe64a75332a32cbd8f6aab9b10299577f20f23f510
BLAKE2b-256 checksum
How to use checksums
b4c2d6303786d5965c1f24142cec4c384719e70886d05eab33d26b5f67db6033
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.5

Release history Release notifications | RSS feed

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.1.4

2 release files

0.1.3

2 release files

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1

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