[rentals] Use widget_tweaks to apply CSS classes to form fields
... instead of subclassing ModelForm to apply a class to all fields
This commit is contained in:
parent
6fad8d534e
commit
5ae60be3b4
@ -3,14 +3,7 @@ from django import forms
|
|||||||
from rentals.models import LockerInfo
|
from rentals.models import LockerInfo
|
||||||
|
|
||||||
|
|
||||||
class BoostrapModelForm(forms.ModelForm):
|
class LockerInfoForm(forms.ModelForm):
|
||||||
def __init__(self, *args, **kwargs):
|
|
||||||
super().__init__(*args, **kwargs)
|
|
||||||
for field in self.fields.values():
|
|
||||||
field.widget.attrs["class"] = "form-control"
|
|
||||||
|
|
||||||
|
|
||||||
class LockerInfoForm(BoostrapModelForm):
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = LockerInfo
|
model = LockerInfo
|
||||||
fields = [
|
fields = [
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
{% extends "base.dj.html" %}
|
{% extends "base.dj.html" %}
|
||||||
|
|
||||||
|
{% load widget_tweaks %}
|
||||||
|
|
||||||
{% block title %}Lockers Index{% endblock %}
|
{% block title %}Lockers Index{% endblock %}
|
||||||
{% block admin_link %}
|
{% block admin_link %}
|
||||||
{% url 'admin:app_list' 'rentals' %}
|
{% url 'admin:app_list' 'rentals' %}
|
||||||
@ -81,7 +83,7 @@
|
|||||||
<fieldset {{ perms.rentals.change_lockerinfo|yesno:",disabled" }}>
|
<fieldset {{ perms.rentals.change_lockerinfo|yesno:",disabled" }}>
|
||||||
{% for field in locker_form.visible_fields %}
|
{% for field in locker_form.visible_fields %}
|
||||||
<div class="form-floating mb-3">
|
<div class="form-floating mb-3">
|
||||||
{{ field }}
|
{% render_field field class+="form-control" %}
|
||||||
{{ field.label_tag }}
|
{{ field.label_tag }}
|
||||||
{{ field.errors }}
|
{{ field.errors }}
|
||||||
{% if field.help_text %}
|
{% if field.help_text %}
|
||||||
|
Loading…
Reference in New Issue
Block a user