aboutsummaryrefslogtreecommitdiff
path: root/models.py
diff options
context:
space:
mode:
authorAlban Gruin2017-09-04 19:36:16 +0200
committerAlban Gruin2017-09-04 19:36:16 +0200
commit6302ee0f04702c21101f07377b5f2484a165cf16 (patch)
treefa7f6fb3e3becf6bd7caef14288f9dd3083c7d15 /models.py
parenta6c5bfa4796081747e04ae4047007d5c8ad23164 (diff)
On retrouve le parent d’un groupe lorsqu’on l’enregistre
Diffstat (limited to 'models.py')
-rw-r--r--models.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/models.py b/models.py
index 53bcef7..1843a9f 100644
--- a/models.py
+++ b/models.py
@@ -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()