aboutsummaryrefslogtreecommitdiffstats
path: root/ctrack
diff options
context:
space:
mode:
authorMR Lemon <matt@matthewlemon>2020-05-02 14:49:11 +0100
committerMR Lemon <matt@matthewlemon>2020-05-02 14:49:11 +0100
commit51797f3868ad9fe2a0ff59a6732ed54d377cc5a4 (patch)
tree9a90779836689fc0fc6b1795026055c0cbf6af4e /ctrack
parentb562707e4598c7f04463e688928b90b47196b6c1 (diff)
still working on org address form
Diffstat (limited to 'ctrack')
-rw-r--r--ctrack/organisations/forms.py6
-rw-r--r--ctrack/organisations/views.py15
2 files changed, 10 insertions, 11 deletions
diff --git a/ctrack/organisations/forms.py b/ctrack/organisations/forms.py
index 0caf628..d60172a 100644
--- a/ctrack/organisations/forms.py
+++ b/ctrack/organisations/forms.py
@@ -44,6 +44,12 @@ class OrganisationCreateForm(forms.ModelForm):
"designation_type": "This is probably defined in the Reguation",
}
+ def save(self, **kwargs):
+ org = super().save(commit=False)
+ org.updated_by = kwargs["user"]
+ org.save()
+ return org
+
class AddressCreateForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
diff --git a/ctrack/organisations/views.py b/ctrack/organisations/views.py
index ab090a7..ef07c1b 100644
--- a/ctrack/organisations/views.py
+++ b/ctrack/organisations/views.py
@@ -3,6 +3,7 @@ from typing import Dict
from django.contrib.auth.mixins import LoginRequiredMixin
from django.db import transaction
+from django.utils import timezone
from django.views.generic import DetailView, ListView, CreateView
from .forms import OrganisationCreateForm, AddressInlineForm
@@ -12,16 +13,7 @@ from .models import Organisation
class OrganisationCreateWithAddress(CreateView):
model = Organisation
template_name = "organisations/org_create_formset.html"
- fields = [
- "name",
- "submode",
- "oes",
- "designation_type",
- "registered_company_name",
- "registered_company_number",
- "comments",
- "active"
- ]
+ form_class = OrganisationCreateForm
def get_context_data(self, **kwargs):
data = super().get_context_data(**kwargs)
@@ -34,8 +26,9 @@ class OrganisationCreateWithAddress(CreateView):
def form_valid(self, form):
context = self.get_context_data()
addresses = context["addresses"]
+ user = self.request.user
with transaction.atomic():
- self.object = form.save()
+ self.object = form.save(user=user)
if addresses.is_valid():
addresses.instance = self.object