diff options
author | Matthew Lemon <lemon@matthewlemon.com> | 2020-05-25 16:09:41 +0100 |
---|---|---|
committer | Matthew Lemon <lemon@matthewlemon.com> | 2020-05-25 16:09:41 +0100 |
commit | 75cad4697874dc1e06f1758dd9915394f7287d63 (patch) | |
tree | db1d5e7a87f19d92bac5019c898fbc75cca418ba /ctrack/organisations | |
parent | 4aaa68109434e04d1103710d675efd075b2f744a (diff) |
in trying to create a Stakeholder model referenced from User, have removed updated_by fields in other models and factories - was getting circular dep error
Diffstat (limited to 'ctrack/organisations')
-rw-r--r-- | ctrack/organisations/admin.py | 4 | ||||
-rw-r--r-- | ctrack/organisations/migrations/0005_auto_20200525_1502.py | 29 | ||||
-rw-r--r-- | ctrack/organisations/models.py | 22 | ||||
-rw-r--r-- | ctrack/organisations/templates/organisations/organisation_detail.html | 2 | ||||
-rw-r--r-- | ctrack/organisations/tests/factories.py | 2 | ||||
-rw-r--r-- | ctrack/organisations/views.py | 23 |
6 files changed, 60 insertions, 22 deletions
diff --git a/ctrack/organisations/admin.py b/ctrack/organisations/admin.py index dbd7239..0a3827d 100644 --- a/ctrack/organisations/admin.py +++ b/ctrack/organisations/admin.py @@ -1,6 +1,6 @@ from django.contrib import admin -from .models import Organisation, Address, AddressType, Person, Role, Mode, Submode +from .models import Address, AddressType, Mode, Organisation, Person, Role, Submode # So we can get the organisation name - a reverse lookup @@ -24,7 +24,7 @@ class AddressInLine(admin.StackedInline): class OrganisationAdmin(admin.ModelAdmin): inlines = [AddressInLine] - list_display = ("name", "submode", "date_updated", "updated_by") + list_display = ("name", "submode", "date_updated") class PersonAdmin(admin.ModelAdmin): diff --git a/ctrack/organisations/migrations/0005_auto_20200525_1502.py b/ctrack/organisations/migrations/0005_auto_20200525_1502.py new file mode 100644 index 0000000..921fdbb --- /dev/null +++ b/ctrack/organisations/migrations/0005_auto_20200525_1502.py @@ -0,0 +1,29 @@ +# Generated by Django 3.0.5 on 2020-05-25 15:02 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('organisations', '0004_auto_20200513_1441'), + ] + + operations = [ + migrations.RemoveField( + model_name='organisation', + name='updated_by', + ), + migrations.RemoveField( + model_name='person', + name='updated_by', + ), + migrations.CreateModel( + name='Stakeholder', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('person', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='organisations.Person')), + ], + ), + ] diff --git a/ctrack/organisations/models.py b/ctrack/organisations/models.py index b11e97b..92e4bc6 100644 --- a/ctrack/organisations/models.py +++ b/ctrack/organisations/models.py @@ -47,7 +47,7 @@ class Person(models.Model): to handle when Users are deleted from the system, preventing the Person objects related to them being deleted also. """ - return get_user_model().objects.get_or_create(username='DELETED USER')[0] + return get_user_model().objects.get_or_create(username="DELETED USER")[0] primary_nis_contact = models.BooleanField( default=False, verbose_name="Primary NIS contact" @@ -65,7 +65,9 @@ class Person(models.Model): mobile = models.CharField(max_length=20, blank=True) landline = models.CharField(max_length=20, blank=True) date_updated = models.DateField(auto_now=True) - updated_by = models.ForeignKey(get_user_model(), on_delete=models.SET(get_sentinel_user)) + # updated_by = models.ForeignKey( + # get_user_model(), on_delete=models.SET(get_sentinel_user) + # ) clearance = models.IntegerField(choices=CLEARANCE_LEVEL, default=1) clearance_sponsor = models.CharField(max_length=100, blank=True) clearance_start_date = models.DateField(blank=True, null=True) @@ -74,7 +76,11 @@ class Person(models.Model): active = models.BooleanField(default=True) date_ended = models.DateField(blank=True, null=True) predecessor = models.ForeignKey( - "self", blank=True, on_delete=models.CASCADE, related_name="previous_person", null=True + "self", + blank=True, + on_delete=models.CASCADE, + related_name="previous_person", + null=True, ) comments = models.TextField(max_length=1000, blank=True) @@ -116,7 +122,7 @@ class Organisation(models.Model): to handle when Users are deleted from the system, preventing the Organisations related to them being deleted also. """ - return get_user_model().objects.get_or_create(username='DELETED USER')[0] + return get_user_model().objects.get_or_create(username="DELETED USER")[0] name = models.CharField(max_length=255) slug = AutoSlugField(populate_from=["name"]) @@ -128,7 +134,9 @@ class Organisation(models.Model): registered_company_name = models.CharField(max_length=255, blank=True) registered_company_number = models.CharField(max_length=100, blank=True) date_updated = models.DateField(auto_now=True) - updated_by = models.ForeignKey(get_user_model(), on_delete=models.SET(get_sentinel_user)) + # updated_by = models.ForeignKey( + # get_user_model(), on_delete=models.SET(get_sentinel_user) + # ) comments = models.TextField(max_length=500, blank=True, null=True) active = models.BooleanField(default=True) @@ -166,3 +174,7 @@ class Address(models.Model): class Meta: verbose_name_plural = "Addresses" + + +class Stakeholder(models.Model): + person = models.ForeignKey(Person, on_delete=models.CASCADE) diff --git a/ctrack/organisations/templates/organisations/organisation_detail.html b/ctrack/organisations/templates/organisations/organisation_detail.html index daec5a9..2479f50 100644 --- a/ctrack/organisations/templates/organisations/organisation_detail.html +++ b/ctrack/organisations/templates/organisations/organisation_detail.html @@ -48,7 +48,7 @@ </tr> <tr> <td><strong>Updated By:</strong></td> - <td>{{ object.updated_by }}</td> + <td>REMOVED</td> </tr> <tr> <td><strong>Active:</strong></td> diff --git a/ctrack/organisations/tests/factories.py b/ctrack/organisations/tests/factories.py index 7acd887..4f4928c 100644 --- a/ctrack/organisations/tests/factories.py +++ b/ctrack/organisations/tests/factories.py @@ -51,7 +51,6 @@ class OrganisationFactory(DjangoModelFactory): registered_company_name = Faker("company") registered_company_number = Faker("numerify", text="######") date_updated = Faker("date_this_year", before_today=True) - updated_by = SubFactory(UserFactory) comments = Faker("paragraph", nb_sentences=3) active = True @@ -99,7 +98,6 @@ class PersonFactory(DjangoModelFactory): mobile = Faker("cellphone_number", locale="en_GB") landline = Faker("phone_number", locale="en_GB") date_updated = factory.LazyFunction(datetime.now) - updated_by = SubFactory(UserFactory) clearance = factory.LazyFunction(lambda: random.randint(1, 6)) clearance_sponsor = Faker("name", locale="en_GB") clearance_start_date = factory.LazyFunction(datetime.now) diff --git a/ctrack/organisations/views.py b/ctrack/organisations/views.py index fe88728..2476453 100644 --- a/ctrack/organisations/views.py +++ b/ctrack/organisations/views.py @@ -1,12 +1,11 @@ -from typing import Any -from typing import Dict +from typing import Any, Dict from django.contrib.auth.mixins import LoginRequiredMixin from django.db import transaction from django.urls import reverse_lazy -from django.views.generic import DetailView, ListView, CreateView +from django.views.generic import CreateView, DetailView, ListView -from .forms import OrganisationCreateForm, AddressInlineFormSet +from .forms import AddressInlineFormSet, OrganisationCreateForm from .models import Organisation @@ -27,7 +26,7 @@ class OrganisationCreate(LoginRequiredMixin, CreateView): context = self.get_context_data() addresses = context["addresses"] with transaction.atomic(): - form.instance.updated_by = self.request.user + # form.instance.updated_by = self.request.user REMOVED updated_by self.object = form.save() if addresses.is_valid(): addresses.instance = self.object @@ -52,18 +51,18 @@ class OrganisationDetailView(LoginRequiredMixin, DetailView): def get_context_data(self, **kwargs: Any) -> Dict[str, Any]: context = super().get_context_data() - org = kwargs['object'] + org = kwargs["object"] no_addr = org.addresses.count() if no_addr > 1: - context['no_addr'] = no_addr + context["no_addr"] = no_addr addr = org.addresses.all() - context['addr'] = addr + context["addr"] = addr else: - context['no_addr'] = 1 + context["no_addr"] = 1 addr = org.addresses.first() - context['addr'] = addr + context["addr"] = addr people = org.person_set.all() - context['people'] = people + context["people"] = people applicable_systems = org.applicablesystem_set.all() - context['applicable_systems'] = applicable_systems + context["applicable_systems"] = applicable_systems return context |