Skip to main content

django-forms-fieldset

https://github.com/hadpro24/django-forms-fieldset/actions https://pypi.org/project/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>
	{{ 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 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-1.0.1.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-1.0.1-py3-none-any.whl (278.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django-forms-fieldset-1.0.1.tar.gz
  • Upload date:
  • Size: 276.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.5.0 pkginfo/1.8.2 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.10

File hashes

Hashes for django-forms-fieldset-1.0.1.tar.gz
Algorithm Hash digest
SHA256 c574d7dffdaf1f7b2c9c51db0e6ad13e6b7eabed2008a817bbd8a55e93fa9eb7
MD5 7417aa83ff4a29cd6e017e1cee67a826
BLAKE2b-256 b85f32dc9f2c1def417da4b49f67f83619d826f1567d32e46c72a14ec61f3dd1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: django_forms_fieldset-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 278.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.5.0 pkginfo/1.8.2 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.10

File hashes

Hashes for django_forms_fieldset-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0f9c059fa8e660a7dcd4d309a8da4687531f76dfa8eb3e5c6e076ae1f643b9e9
MD5 a35a5583b1865cd2d1d380794cf7249b
BLAKE2b-256 728f12b6904f9480cd8e6fc7e756ce03d56c29c0e81bf9d86698fd96f65d8c8d

See more details on using hashes here.

Release history Release notifications | RSS feed

1.0.2

2 files

This release

1.0.1 This release

2 files

1.0.0

2 files

0.1.4

2 files

0.1.3

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