feat(people): Add organisation field to Person

See #1
This commit is contained in:
James Graham
2020-02-25 08:52:11 +00:00
parent 9210636475
commit 5e6065951f
2 changed files with 39 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
# Generated by Django 2.2.10 on 2020-02-25 08:49
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('people', '0010_add_country_fields'),
]
operations = [
migrations.CreateModel(
name='Organisation',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=255)),
],
),
migrations.AddField(
model_name='person',
name='organisation',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='members', to='people.Organisation'),
),
]

View File

@@ -17,6 +17,14 @@ class User(AbstractUser):
"""
class Organisation(models.Model):
"""
Organisation to which a :class:`Person` belongs.
"""
name = models.CharField(max_length=255,
blank=False, null=False)
class Person(models.Model):
"""
A person may be a member of the BRECcIA core team or an external stakeholder.
@@ -77,6 +85,11 @@ class Person(models.Model):
country_of_residence = CountryField(blank=True, null=True)
organisation = models.ForeignKey(Organisation,
on_delete=models.PROTECT,
related_name='members',
blank=True, null=True)
@property
def relationships(self):
return self.relationships_as_source.all().union(