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/users | |
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/users')
-rw-r--r-- | ctrack/users/migrations/0005_delete_userprofile.py | 16 | ||||
-rw-r--r-- | ctrack/users/migrations/0006_user_stakeholder.py | 20 | ||||
-rw-r--r-- | ctrack/users/models.py | 11 | ||||
-rw-r--r-- | ctrack/users/stakeholder.py | 4 | ||||
-rw-r--r-- | ctrack/users/tests/test_models.py | 2 |
5 files changed, 44 insertions, 9 deletions
diff --git a/ctrack/users/migrations/0005_delete_userprofile.py b/ctrack/users/migrations/0005_delete_userprofile.py new file mode 100644 index 0000000..42f62bb --- /dev/null +++ b/ctrack/users/migrations/0005_delete_userprofile.py @@ -0,0 +1,16 @@ +# Generated by Django 3.0.5 on 2020-05-25 14:41 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('users', '0004_auto_20200524_1945'), + ] + + operations = [ + migrations.DeleteModel( + name='UserProfile', + ), + ] diff --git a/ctrack/users/migrations/0006_user_stakeholder.py b/ctrack/users/migrations/0006_user_stakeholder.py new file mode 100644 index 0000000..d8a3089 --- /dev/null +++ b/ctrack/users/migrations/0006_user_stakeholder.py @@ -0,0 +1,20 @@ +# 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', '0005_auto_20200525_1502'), + ('users', '0005_delete_userprofile'), + ] + + operations = [ + migrations.AddField( + model_name='user', + name='stakeholder', + field=models.OneToOneField(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='organisations.Stakeholder'), + ), + ] diff --git a/ctrack/users/models.py b/ctrack/users/models.py index 8f07b15..b53c217 100644 --- a/ctrack/users/models.py +++ b/ctrack/users/models.py @@ -1,14 +1,17 @@ from django.contrib.auth.models import AbstractUser -from django.db.models import CharField +from django.db import models from django.urls import reverse from django.utils.translation import ugettext_lazy as _ +from ctrack.organisations.models import Stakeholder + class User(AbstractUser): - # First Name and Last Name do not cover name patterns - # around the globe. - name = CharField(_("Name of User"), blank=True, max_length=255) + name = models.CharField(_("Name of User"), blank=True, max_length=255) + stakeholder = models.OneToOneField( + Stakeholder, on_delete=models.CASCADE, null=True, blank=True + ) def get_absolute_url(self): return reverse("users:detail", kwargs={"username": self.username}) diff --git a/ctrack/users/stakeholder.py b/ctrack/users/stakeholder.py index d15dd39..a8b4329 100644 --- a/ctrack/users/stakeholder.py +++ b/ctrack/users/stakeholder.py @@ -1,7 +1,3 @@ from django.db import models from ctrack.organisations.models import Person - - -class Stakeholder(models.Model): - person = models.ForeignKey(Person, on_delete=models.CASCADE) diff --git a/ctrack/users/tests/test_models.py b/ctrack/users/tests/test_models.py index 2d45cca..96bd4b9 100644 --- a/ctrack/users/tests/test_models.py +++ b/ctrack/users/tests/test_models.py @@ -1,6 +1,6 @@ import pytest -from ctrack.users.stakeholder import Stakeholder +from ctrack.organisations.models import Stakeholder pytestmark = pytest.mark.django_db |