aboutsummaryrefslogtreecommitdiffstats
path: root/ctrack/organisations/views.py
diff options
context:
space:
mode:
authorMR Lemon <matt@matthewlemon>2020-05-01 17:30:48 +0100
committerMR Lemon <matt@matthewlemon>2020-05-01 17:31:03 +0100
commit989b3bf9259b06ed3542d16a81712635ef492c33 (patch)
treef3f53e9000712568942e658dfbd889068bed2fd4 /ctrack/organisations/views.py
parentdbe4555b17e2dd0d49b8c4879252692f75f8fe42 (diff)
started to put in an inlineformset!
Diffstat (limited to '')
-rw-r--r--ctrack/organisations/views.py19
1 files changed, 17 insertions, 2 deletions
diff --git a/ctrack/organisations/views.py b/ctrack/organisations/views.py
index 74b290e..cad729d 100644
--- a/ctrack/organisations/views.py
+++ b/ctrack/organisations/views.py
@@ -2,10 +2,25 @@ from typing import Any
from typing import Dict
from django.contrib.auth.mixins import LoginRequiredMixin
+from django.forms import inlineformset_factory
+from django.http import HttpResponseRedirect
+from django.shortcuts import render
from django.views.generic import DetailView, ListView, CreateView
-from .forms import OrganisationCreateForm
-from .models import Organisation
+from .forms import OrganisationCreateForm, AddressCreateForm
+from .models import Organisation, Address
+
+
+def create_org_with_address(request):
+ OrgCreateInlineFormSet = inlineformset_factory(Organisation, Address, exclude=(), can_delete=False, form=AddressCreateForm, extra=3)
+ if request.method == "POST":
+ formset = OrgCreateInlineFormSet(request.POST)
+ if formset.is_valid():
+ formset.save()
+ return HttpResponseRedirect("/")
+ else:
+ formset = OrgCreateInlineFormSet()
+ return render(request, "organisations/org_create_formset.html", {"formset": formset})
class OrganisationCreate(LoginRequiredMixin, CreateView):