aboutsummaryrefslogtreecommitdiffstats
path: root/ctrack/organisations/forms.py
diff options
context:
space:
mode:
Diffstat (limited to 'ctrack/organisations/forms.py')
-rw-r--r--ctrack/organisations/forms.py39
1 files changed, 15 insertions, 24 deletions
diff --git a/ctrack/organisations/forms.py b/ctrack/organisations/forms.py
index ac96bcb..2fe5033 100644
--- a/ctrack/organisations/forms.py
+++ b/ctrack/organisations/forms.py
@@ -1,5 +1,5 @@
from crispy_forms.helper import FormHelper
-from crispy_forms.layout import Layout, Fieldset, ButtonHolder, Submit, Button, Field
+from crispy_forms.layout import Layout, Fieldset, Field, ButtonHolder, Submit
from django import forms
from django.forms import inlineformset_factory
from django.urls import reverse
@@ -24,10 +24,6 @@ class OrganisationCreateForm(forms.ModelForm):
"comments",
"active"
),
- ButtonHolder(
- Submit("submit", "Submit", css_class="btn-primary"),
- Button("cancel", "Cancel", onclick=f"location.href='{cancel_redirect}';", css_class="btn-danger")
- )
)
class Meta:
@@ -46,32 +42,27 @@ class OrganisationCreateForm(forms.ModelForm):
class AddressCreateForm(forms.ModelForm):
- def __init__(self, *args, **kwargs):
- super().__init__(*args, **kwargs)
- cancel_redirect = reverse("organisations:list")
- self.helper = FormHelper(self)
- self.helper.layout = Layout(
- Fieldset(
- "Add an address",
- "type",
- "line1",
- "line2",
- "line3",
- "city",
- "county",
- "postcode",
- "country",
- "other_details"
- )
- )
-
class Meta:
model = Address
fields = ('type', 'line1', 'line2', 'line3', 'city', 'county', 'postcode',
'country', 'other_details')
+# https://dev.to/zxenia/django-inline-formsets-with-class-based-views-and-crispy-forms-14o6
+# good advice on setting up the inlineformset - with crispy forms too
AddressInlineFormSet = inlineformset_factory(Organisation, Address,
fields=("type", "line1", "line2", "line3", "city",
"county", "postcode", "country", "other_details"),
form=AddressCreateForm)
+
+
+class OrganisationInlineFormSetHelper(FormHelper):
+ def __init__(self, *args, **kwargs):
+ super().__init__(*args, **kwargs)
+ self.form_method = "post"
+ self.layout = Layout(
+ "line1",
+ "line2"
+ )
+ self.render_required_fields = True
+ self.add_input(Submit("submit", "Save"))