From 0785f1e1d436bee1f81c4d04793141e221bb0211 Mon Sep 17 00:00:00 2001 From: Ori Hoch Date: Sun, 20 Mar 2016 22:50:48 +0200 Subject: [PATCH] quick and dirty hack to allow adding person alias from member admin --- mks/models.py | 10 ++++++++++ persons/models.py | 5 +++++ 2 files changed, 15 insertions(+) diff --git a/mks/models.py b/mks/models.py index 1cd0f17f..234968ac 100644 --- a/mks/models.py +++ b/mks/models.py @@ -182,6 +182,16 @@ class MemberAltname(models.Model): member = models.ForeignKey('Member') name = models.CharField(max_length=64) + def save(self, **kwargs): + super(MemberAltname, self).save(**kwargs) + [person.add_alias(self.name) for person in self.member.person.all()] + + def delete(self, **kwargs): + persons = list(self.member.person.all()) + name = self.name + super(MemberAltname, self).delete(**kwargs) + [person.del_alias(name) for person in persons] + class Member(models.Model): id = models.IntegerField(primary_key=True, diff --git a/persons/models.py b/persons/models.py index 1995a716..f852f3ba 100644 --- a/persons/models.py +++ b/persons/models.py @@ -164,6 +164,11 @@ def create_user(self, username=None, password=None): self.save() return user + def add_alias(self, alias): + PersonAlias.objects.get_or_create(name=alias, person=self) + + def del_alias(self, alias): + PersonAlias.objects.filter(name=alias, person=self).delete() @receiver(post_save, sender=Member) def member_post_save(sender, **kwargs):