Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

Commit

Permalink
quick and dirty hack to allow adding person alias from member admin
Browse files Browse the repository at this point in the history
  • Loading branch information
OriHoch committed Mar 20, 2016
1 parent 7425b54 commit 0785f1e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
10 changes: 10 additions & 0 deletions mks/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions persons/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 0785f1e

Please sign in to comment.