Skip to main content

Django form fieldset inspire django admin fieldset. (fork of original reposity by hadpro24 to support Django 5.1 and newer releases)

Project description

django5-forms-fieldset

https://github.com/NCIAdmin/django5-forms-fieldset/actions https://pypi.org/project/django5-forms-fieldset/

Django form fieldset inspire django admin fieldset (fork of original reposity by hadpro24 to support Django 5.1 and newer releases)

Installation

pip install django5-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

Release

- version 1.0.0
	fix for Django 5.1 and newer

Credit

NCI IT Team Jake Morgan Jochen Winzer

Orginal Contributor: -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

django5_forms_fieldset-1.0.0.tar.gz (281.1 kB view details)

Uploaded Source

Built Distribution

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

django5_forms_fieldset-1.0.0-py3-none-any.whl (287.8 kB view details)

Uploaded Python 3

File details

Details for the file django5_forms_fieldset-1.0.0.tar.gz.

File metadata

  • Download URL: django5_forms_fieldset-1.0.0.tar.gz
  • Upload date:
  • Size: 281.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for django5_forms_fieldset-1.0.0.tar.gz
Algorithm Hash digest
SHA256 4a189e2a97dbce4f547d818cff8c555764197ac1ff3f4862cef519018d1f94f9
MD5 16fa96ca47637ef9789c8ee6b153c5de
BLAKE2b-256 8611b62bdef074802e3fb8566afbec4a934af446ab318148e7611727c86f9cec

See more details on using hashes here.

File details

Details for the file django5_forms_fieldset-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django5_forms_fieldset-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e9b1e7576e8a49c3b5f085406bb5b52e35331fc34b641f3afca4173062ee03f5
MD5 42e610fae9c0df9da5fbc7e93c0746f2
BLAKE2b-256 b090f084d437976dd3e7ca4e4e4e10e02c6b697928bc3688ca3554e6bbd7be97

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page