fix: revert relationship link change

Fixes issue where migrations will not run on MySQL
This commit is contained in:
James Graham
2020-12-07 17:37:47 +00:00
parent 80491623de
commit 76fcb7ceb2
3 changed files with 10 additions and 31 deletions

View File

@@ -119,7 +119,7 @@ class Person(models.Model):
'self',
related_name='relationship_sources',
through='Relationship',
through_fields=('source', 'target_person'),
through_fields=('source', 'target'),
symmetrical=False)
@property

View File

@@ -52,7 +52,7 @@ class Relationship(models.Model):
class Meta:
constraints = [
models.UniqueConstraint(fields=['source', 'target_person'],
models.UniqueConstraint(fields=['source', 'person'],
name='unique_relationship'),
]
@@ -62,11 +62,11 @@ class Relationship(models.Model):
blank=False, null=False)
#: Person with whom the relationship is reported
target_person = models.ForeignKey(Person,
related_name='relationships_as_target',
on_delete=models.CASCADE,
blank=False,
null=False)
target = models.ForeignKey(Person,
related_name='relationships_as_target',
on_delete=models.CASCADE,
blank=False,
null=False)
# blank=True,
# null=True)
@@ -83,13 +83,6 @@ class Relationship(models.Model):
#: When was this marked as expired? Default None means it has not expired
expired = models.DateTimeField(blank=True, null=True)
@property
def target(self) -> Person:
if self.target_person:
return self.target_person
raise ObjectDoesNotExist('Relationship has no target linked')
@property
def current_answers(self) -> 'RelationshipAnswerSet':
return self.answer_sets.last()
@@ -107,8 +100,8 @@ class Relationship(models.Model):
@raise Relationship.DoesNotExist: When the reverse relationship is not known
"""
return type(self).objects.get(source=self.target_person,
target_person=self.source)
return type(self).objects.get(source=self.target,
target=self.source)
class RelationshipAnswerSet(AnswerSet):