diff options
Diffstat (limited to 'ctrack/organisations')
-rw-r--r-- | ctrack/organisations/admin.py | 24 | ||||
-rw-r--r-- | ctrack/organisations/migrations/0009_auto_20200124_1623.py | 53 | ||||
-rw-r--r-- | ctrack/organisations/migrations/0010_auto_20200124_1629.py | 23 | ||||
-rw-r--r-- | ctrack/organisations/models.py | 24 |
4 files changed, 121 insertions, 3 deletions
diff --git a/ctrack/organisations/admin.py b/ctrack/organisations/admin.py index f8ad2aa..5ae61d5 100644 --- a/ctrack/organisations/admin.py +++ b/ctrack/organisations/admin.py @@ -1,6 +1,15 @@ from django.contrib import admin -from .models import Organisation, Address, AddressType +from .models import Organisation, Address, AddressType, Person, Role + + +# So we can get the organisation name - a reverse lookup +def get_organisation_name(person): + return Organisation.objects.filter(person__name=person).first().name + + +# We need this to ensure the column header in the admin does't read the func name +get_organisation_name.short_description = 'Organisation' class AddressTypeAdmin(admin.ModelAdmin): @@ -15,9 +24,20 @@ class AddressInLine(admin.StackedInline): class OrganisationAdmin(admin.ModelAdmin): inlines = [AddressInLine,] - list_display = ('slug', 'name') + list_display = ('name',) + + +class PersonAdmin(admin.ModelAdmin): + model = Person + list_display = ['name', get_organisation_name, 'email', 'mobile'] + + +class RoleAdmin(admin.ModelAdmin): + model = Role # Register your models here. admin.site.register(Organisation, OrganisationAdmin) admin.site.register(AddressType, AddressTypeAdmin) +admin.site.register(Role, RoleAdmin) +admin.site.register(Person, PersonAdmin) diff --git a/ctrack/organisations/migrations/0009_auto_20200124_1623.py b/ctrack/organisations/migrations/0009_auto_20200124_1623.py new file mode 100644 index 0000000..0b90de4 --- /dev/null +++ b/ctrack/organisations/migrations/0009_auto_20200124_1623.py @@ -0,0 +1,53 @@ +# Generated by Django 2.2.9 on 2020-01-24 16:23 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('organisations', '0008_auto_20200123_1657'), + ] + + operations = [ + migrations.CreateModel( + name='Role', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=100)), + ], + ), + migrations.AlterField( + model_name='address', + name='county', + field=models.CharField(blank=True, max_length=100), + ), + migrations.AlterField( + model_name='address', + name='line2', + field=models.CharField(blank=True, max_length=255), + ), + migrations.AlterField( + model_name='address', + name='line3', + field=models.CharField(blank=True, max_length=255), + ), + migrations.AlterField( + model_name='address', + name='other_details', + field=models.CharField(blank=True, max_length=255), + ), + migrations.CreateModel( + name='Person', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=255)), + ('email', models.EmailField(max_length=254)), + ('mobile', models.CharField(max_length=20)), + ('landline', models.CharField(max_length=20)), + ('organisation', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='organisations.Organisation')), + ('role', models.ManyToManyField(to='organisations.Role')), + ], + ), + ] diff --git a/ctrack/organisations/migrations/0010_auto_20200124_1629.py b/ctrack/organisations/migrations/0010_auto_20200124_1629.py new file mode 100644 index 0000000..de2b751 --- /dev/null +++ b/ctrack/organisations/migrations/0010_auto_20200124_1629.py @@ -0,0 +1,23 @@ +# Generated by Django 2.2.9 on 2020-01-24 16:29 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('organisations', '0009_auto_20200124_1623'), + ] + + operations = [ + migrations.AlterField( + model_name='person', + name='landline', + field=models.CharField(blank=True, max_length=20), + ), + migrations.AlterField( + model_name='person', + name='mobile', + field=models.CharField(blank=True, max_length=20), + ), + ] diff --git a/ctrack/organisations/models.py b/ctrack/organisations/models.py index 0ecac94..cc97a04 100644 --- a/ctrack/organisations/models.py +++ b/ctrack/organisations/models.py @@ -13,8 +13,30 @@ class AddressType(models.Model): return self.descriptor +class Role(models.Model): + name = models.CharField(max_length=100) + + def __str__(self): + return self.name + + +class Person(models.Model): + name = models.CharField(max_length=255) + organisation = models.ForeignKey("Organisation", on_delete=models.CASCADE) + role = models.ManyToManyField(Role) + email = models.EmailField() + mobile = models.CharField(max_length=20, blank=True) + landline = models.CharField(max_length=20, blank=True) + + def __str__(self): + return self.name + + def get_organisation_name(self): + return self.organisation.name + + class Organisation(models.Model): - name = models.CharField(max_length=255, blank=False) + name = models.CharField(max_length=255) slug = AutoSlugField(populate_from=['name']) def get_absolute_url(self): |