Skip to content

Commit

Permalink
Fix tests; add related_name to dob and dod
Browse files Browse the repository at this point in the history
  • Loading branch information
XanderVertegaal committed Feb 3, 2024
1 parent e25860a commit 37ca716
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 4.2.7 on 2024-02-02 15:17
# Generated by Django 4.2.7 on 2024-02-03 10:53

import django.core.validators
from django.db import migrations, models
Expand All @@ -21,7 +21,7 @@ class Migration(migrations.Migration):
('year_lower', models.IntegerField(default=400, help_text='The earliest possible year for this value', validators=[django.core.validators.MinValueValidator(400), django.core.validators.MaxValueValidator(800)])),
('year_upper', models.IntegerField(default=800, help_text='The latest possible year for this value', validators=[django.core.validators.MinValueValidator(400), django.core.validators.MaxValueValidator(800)])),
('year_exact', models.IntegerField(blank=True, help_text='The exact year of the value (if known). This will override the values in the lower and upper bounds fields.', null=True, validators=[django.core.validators.MinValueValidator(400), django.core.validators.MaxValueValidator(800)])),
('person', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='person.person')),
('person', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='date_of_death', to='person.person')),
],
options={
'abstract': False,
Expand All @@ -36,7 +36,7 @@ class Migration(migrations.Migration):
('year_lower', models.IntegerField(default=400, help_text='The earliest possible year for this value', validators=[django.core.validators.MinValueValidator(400), django.core.validators.MaxValueValidator(800)])),
('year_upper', models.IntegerField(default=800, help_text='The latest possible year for this value', validators=[django.core.validators.MinValueValidator(400), django.core.validators.MaxValueValidator(800)])),
('year_exact', models.IntegerField(blank=True, help_text='The exact year of the value (if known). This will override the values in the lower and upper bounds fields.', null=True, validators=[django.core.validators.MinValueValidator(400), django.core.validators.MaxValueValidator(800)])),
('person', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='person.person')),
('person', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='date_of_birth', to='person.person')),
],
options={
'abstract': False,
Expand Down
8 changes: 6 additions & 2 deletions backend/person/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ class PersonDateOfBirth(LettercraftDate, Field, models.Model):
A relationship between a person and their date of birth.
"""

person = models.OneToOneField(Person, on_delete=models.CASCADE)
person = models.OneToOneField(
Person, related_name="date_of_birth", on_delete=models.CASCADE
)

def __str__(self):
if self.year_exact:
Expand All @@ -79,7 +81,9 @@ class PersonDateOfDeath(LettercraftDate, Field, models.Model):
A relationship between a person and their date of death.
"""

person = models.OneToOneField(Person, on_delete=models.CASCADE)
person = models.OneToOneField(
Person, related_name="date_of_death", on_delete=models.CASCADE
)

def __str__(self):
if self.year_exact:
Expand Down
5 changes: 3 additions & 2 deletions backend/person/tests/test_person_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ def test_person_names(person_unnamed, person_single_name, person_multiple_names)
assert person_single_name.__str__() == "Bert"
assert person_multiple_names.__str__() == "Bert (aka Ernie, Oscar)"


def test_person_date_of_birth(person_with_exact_dob, person_with_approx_dob):
assert person_with_exact_dob.dates_of_birth.first().__str__() == "born in 512"
assert person_with_approx_dob.dates_of_birth.first().__str__() == "born c. 500–525"
assert person_with_exact_dob.date_of_birth.__str__().endswith("born in 512")
assert person_with_approx_dob.date_of_birth.__str__().endswith("born c. 500–525")

0 comments on commit 37ca716

Please sign in to comment.