
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Custom Django form fields and widgets for duration and dynamic text input.
Custom Duration and Dynamic Text Fields for Django Forms
This project provides two custom fields and widgets for Django forms: a DurationField
with a DurationInput
widget and a DynamicTextField
with a DynamicTextWidget
. These fields allow for customizable form inputs, making it easier to handle duration values and dynamic multi-text inputs.
More custom widgets will be added when I have time :D
This project requires Django 3.0+. To install, simply download or clone the repository into your Django project.
git clone https://github.com/Janus-sama/django-duration-and-dynamic-fields.git
Or manually download the files and include them in your project.
Optional Dependencies For better styling of your forms, you can use:
pip install django-crispy-forms django-bootstrap5
Then configure crispy-forms in your settings:
INSTALLED_APPS = [
'crispy_forms',
'crispy_bootstrap5',
# Your other apps
]
CRISPY_ALLOWED_TEMPLATE_PACKS = "bootstrap5"
CRISPY_TEMPLATE_PACK = "bootstrap5"
1. Duration Field
from .widgets import DurationField
class MyForm(forms.Form):
duration = DurationField(label="Duration")
2. Dynamic Text Field
from .widgets import DynamicTextField
class MyForm(forms.Form):
dynamic_text = DynamicTextField(label="Dynamic Text")
This field allows users to dynamically add multiple text inputs, which will be stored as a single string with each entry separated by a semicolon (;).
from django import forms
from .widgets import DurationField, DynamicTextField
class TaskForm(forms.Form):
task_name = forms.CharField(label="Task Name", max_length=100)
task_duration = DurationField(label="Task Duration")
task_notes = DynamicTextField(label="Task Notes")
1. Duration Field You can customize the widget appearance by modifying the unit_choices during initialization. This allows you to restrict the available units.
duration = DurationField(
label="Custom Duration",
widget=DurationInput(unit_choices=[
("days", "Days"),
("weeks", "Weeks"),
])
)
2. Dynamic Text Field You can customize the DynamicTextField widget by specifying the text for the "Add" button during initialization.
dynamic_text = DynamicTextField(
label="Custom Dynamic Text",
widget=DynamicTextWidget(add_text_button_text="Add More Text")
)
The corresponding HTML templates for these custom widgets are included in the widgets/ directory.
dynamic_text_widget.html
duration.html
FAQs
Custom Django form fields and widgets for duration and dynamic text input.
We found that django-flex-widget demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.