diff options
author | Alban Gruin | 2017-09-04 19:36:16 +0200 |
---|---|---|
committer | Alban Gruin | 2017-09-04 19:36:16 +0200 |
commit | 6302ee0f04702c21101f07377b5f2484a165cf16 (patch) | |
tree | fa7f6fb3e3becf6bd7caef14288f9dd3083c7d15 | |
parent | a6c5bfa4796081747e04ae4047007d5c8ad23164 (diff) |
On retrouve le parent d’un groupe lorsqu’on l’enregistre
-rw-r--r-- | models.py | 12 |
1 files changed, 12 insertions, 0 deletions
@@ -92,6 +92,18 @@ class Group(models.Model): self.slug = slugify(self.name) self.mention, self.subgroup, self.td, self.tp = parse_group(self.name) + + group_content_list = [self.mention, self.subgroup, self.td, self.tp] + group_content_keys = ("mention", "subgroup", "td", "tp") + for i in range(len(group_content_list))[::-1]: + if group_content_list[i] is not None: + group_content_list[i] = None + break + + if group_content_list[1] is not None: + group_content = dict(zip(group_content_keys, group_content_list)) + self.parent_group_id = Group.objects.filter(**group_content).first().id + super(Group, self).save() |