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

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-0.1.3.tar.gz (276.9 kB view details)

Uploaded Source

Built Distribution

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

django_forms_fieldset-0.1.3-py3-none-any.whl (277.6 kB view details)

Uploaded Python 3

File details

Details for the file django-forms-fieldset-0.1.3.tar.gz.

File metadata

  • Download URL: django-forms-fieldset-0.1.3.tar.gz
  • Upload date:
  • Size: 276.9 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for django-forms-fieldset-0.1.3.tar.gz
Algorithm Hash digest
SHA256 c76c5749dae87d1f9e058f20cc43333316cae713a8e4ef5a71749c489d9a4913
MD5 098d9d284087804e783c9610dd72d4e2
BLAKE2b-256 c2919ed8d9a142c990fb5398c0b6bcd9c52eeba899bc5561f1df3d91bf641bf2

See more details on using hashes here.

File details

Details for the file django_forms_fieldset-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: django_forms_fieldset-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 277.6 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for django_forms_fieldset-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 578e004767a3a54b33035058f35e4e3add7d5028b49b727ab76941d643b8fac0
MD5 da6401203e46027f97bb31618a9290e4
BLAKE2b-256 50e3d7a1ee4c77343b34ddb5eb4413a4a8013da6098c1ae3f306e995b94e2d90

See more details on using hashes here.

Release history Release notifications | RSS feed

1.0.2

2 files

1.0.1

2 files

1.0.0

2 files

0.1.4

2 files

This release

0.1.3 This release

2 files

0.1.2

2 files

0.1.1

2 files

0.1

2 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