From 9671f76654ed89f76334fbbfd0ec019ec07f5334 Mon Sep 17 00:00:00 2001 From: MR Lemon Date: Tue, 5 May 2020 15:53:26 +0100 Subject: first iteration of a passable create orgnisation form with address! --- ctrack/organisations/forms.py | 12 ++++ .../organisations/org_create_formset.html | 74 +++++++++++++++++++++- ctrack/organisations/views.py | 2 +- 3 files changed, 85 insertions(+), 3 deletions(-) diff --git a/ctrack/organisations/forms.py b/ctrack/organisations/forms.py index ec5c34e..473bc67 100644 --- a/ctrack/organisations/forms.py +++ b/ctrack/organisations/forms.py @@ -35,6 +35,18 @@ class OrganisationCreateForm(forms.ModelForm): class AddressCreateForm(forms.ModelForm): + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.fields["type"].widget.attrs["class"] = "form-control" + self.fields["line1"].widget.attrs["class"] = "form-control" + self.fields["line2"].widget.attrs["class"] = "form-control" + self.fields["line3"].widget.attrs["class"] = "form-control" + self.fields["city"].widget.attrs["class"] = "form-control" + self.fields["county"].widget.attrs["class"] = "form-control" + self.fields["postcode"].widget.attrs["class"] = "form-control" + self.fields["country"].widget.attrs["class"] = "form-control" + self.fields["other_details"].widget.attrs["class"] = "form-control" + class Meta: model = Address fields = ('type', 'line1', 'line2', 'line3', 'city', 'county', 'postcode', diff --git a/ctrack/organisations/templates/organisations/org_create_formset.html b/ctrack/organisations/templates/organisations/org_create_formset.html index 67d308a..a73a2af 100644 --- a/ctrack/organisations/templates/organisations/org_create_formset.html +++ b/ctrack/organisations/templates/organisations/org_create_formset.html @@ -13,6 +13,7 @@
+ {% csrf_token %} {# this is the parent form - in this case the organisation form #}
{{ form.non_field_errors }} @@ -65,10 +66,79 @@
-
Add address:
+ +
Address:
+
- {{ addresses }} + + {{ addresses.management_form }} + + {% for form in addresses %} + + {% if forloop.counter > 1 %} +
Optional (add an alternative address):
+ {% endif %} + +
+ {{ form.non_field_errors }} + + {{ form.type }} + {{ form.type.help_text }} +
+ +
+ {{ form.non_field_errors }} + + {{ form.line1 }} + {{ form.line1.help_text }} +
+ +
+ {{ form.non_field_errors }} + + {{ form.line2 }} + {{ form.line2.help_text }} +
+ +
+ {{ form.non_field_errors }} + + {{ form.line3 }} + {{ form.line3.help_text }} +
+ +
+ {{ form.non_field_errors }} + + {{ form.city }} + {{ form.city.help_text }} +
+ +
+ {{ form.non_field_errors }} + + {{ form.county }} + {{ form.county.help_text }} +
+ +
+ {{ form.non_field_errors }} + + {{ form.postcode }} + {{ form.postcode.help_text }} +
+ +
+ {{ form.non_field_errors }} + + {{ form.country }} + {{ form.country.help_text }} +
+ + {% endfor %} +
+
{# This is the address inlineformset#} diff --git a/ctrack/organisations/views.py b/ctrack/organisations/views.py index 427d385..fe88728 100644 --- a/ctrack/organisations/views.py +++ b/ctrack/organisations/views.py @@ -10,7 +10,7 @@ from .forms import OrganisationCreateForm, AddressInlineFormSet from .models import Organisation -class OrganisationCreate(CreateView): +class OrganisationCreate(LoginRequiredMixin, CreateView): model = Organisation template_name = "organisations/org_create_formset.html" form_class = OrganisationCreateForm -- cgit v1.2.3