diff options
Diffstat (limited to 'ctrack')
-rw-r--r-- | ctrack/conftest.py | 6 | ||||
-rw-r--r-- | ctrack/organisations/admin.py | 16 | ||||
-rw-r--r-- | ctrack/organisations/models.py | 3 | ||||
-rw-r--r-- | ctrack/users/admin.py | 6 | ||||
-rw-r--r-- | ctrack/users/tests/test_models.py | 5 |
5 files changed, 30 insertions, 6 deletions
diff --git a/ctrack/conftest.py b/ctrack/conftest.py index 7412cc4..4fef7a9 100644 --- a/ctrack/conftest.py +++ b/ctrack/conftest.py @@ -35,7 +35,11 @@ def person(user): submode = Submode.objects.create(descriptor="Light Rail", mode=mode) org = OrganisationFactory.create(submode=submode) person = PersonFactory.create( - role=role, predecessor=None, organisation__submode=submode, organisation=org, + first_name="Chinaplate", + role=role, + predecessor=None, + organisation__submode=submode, + organisation=org, ) return person diff --git a/ctrack/organisations/admin.py b/ctrack/organisations/admin.py index 0a3827d..f85ddad 100644 --- a/ctrack/organisations/admin.py +++ b/ctrack/organisations/admin.py @@ -1,6 +1,15 @@ from django.contrib import admin -from .models import Address, AddressType, Mode, Organisation, Person, Role, Submode +from .models import ( + Address, + AddressType, + Mode, + Organisation, + Person, + Role, + Stakeholder, + Submode, +) # So we can get the organisation name - a reverse lookup @@ -16,6 +25,10 @@ class AddressTypeAdmin(admin.ModelAdmin): pass +class StakeholderAdmin(admin.ModelAdmin): + model = Stakeholder + + class AddressInLine(admin.StackedInline): model = Address max_num = 3 @@ -58,3 +71,4 @@ admin.site.register(Role, RoleAdmin) admin.site.register(Person, PersonAdmin) admin.site.register(Mode, ModeAdmin) admin.site.register(Submode, SubmodeAdmin) +admin.site.register(Stakeholder, StakeholderAdmin) diff --git a/ctrack/organisations/models.py b/ctrack/organisations/models.py index 92e4bc6..6a1b4ac 100644 --- a/ctrack/organisations/models.py +++ b/ctrack/organisations/models.py @@ -178,3 +178,6 @@ class Address(models.Model): class Stakeholder(models.Model): person = models.ForeignKey(Person, on_delete=models.CASCADE) + + def __str__(self): + return f"{self.person.first_name} {self.person.last_name}" diff --git a/ctrack/users/admin.py b/ctrack/users/admin.py index 120cc64..7e930d8 100644 --- a/ctrack/users/admin.py +++ b/ctrack/users/admin.py @@ -12,6 +12,8 @@ class UserAdmin(auth_admin.UserAdmin): form = UserChangeForm add_form = UserCreationForm - fieldsets = (("User", {"fields": ("name",)}),) + auth_admin.UserAdmin.fieldsets - list_display = ["username", "name", "is_superuser"] + fieldsets = ( + ("User", {"fields": ("name", "stakeholder")}), + ) + auth_admin.UserAdmin.fieldsets + list_display = ["username", "name", "is_superuser", "stakeholder"] search_fields = ["name"] diff --git a/ctrack/users/tests/test_models.py b/ctrack/users/tests/test_models.py index 96bd4b9..504195f 100644 --- a/ctrack/users/tests/test_models.py +++ b/ctrack/users/tests/test_models.py @@ -16,10 +16,11 @@ def test_user_is_person_object(user): assert user -def test_stakeholder_model(person): +def test_stakeholder_model(person, user): """ A stakeholder is someone who is part of the regime but also has user access to the the system. """ stakeholder = Stakeholder(person=person) - assert stakeholder + user.stakeholder = stakeholder + assert user.stakeholder.person.first_name == "Chinaplate" |