diff options
-rw-r--r-- | admin.py | 2 | ||||
-rw-r--r-- | management/commands/_private.py | 4 | ||||
-rw-r--r-- | models.py | 14 |
3 files changed, 4 insertions, 16 deletions
@@ -34,7 +34,7 @@ class LastUpdateAdmin(admin.ModelAdmin): class GroupAdmin(admin.ModelAdmin): fieldsets = ( (None, {"fields": ("name", "celcat_name", "timetable",)}), - ("Groupes", {"fields": ("mention", "subgroup", "td", "tp", "parent_group",)}),) + ("Groupes", {"fields": ("mention", "subgroup", "td", "tp", "parent",)}),) list_display = ("name", "timetable",) list_filter = ("timetable__name",) readonly_fields = ("celcat_name", "mention", "subgroup", "td", "tp",) diff --git a/management/commands/_private.py b/management/commands/_private.py index dec13cd..c31eb34 100644 --- a/management/commands/_private.py +++ b/management/commands/_private.py @@ -54,12 +54,12 @@ def consolidate_group(group): break if "subgroup" in group_content: - group.parent_group = Group.objects.filter(**group_content).first() + group.parent = Group.objects.filter(**group_content).first() group.save() def consolidate_groups(groups): for group in groups: - if group.parent_group == None: + if group.parent == None: consolidate_group(group) def delete_courses_in_week(timetable, year, week): @@ -72,7 +72,7 @@ class Group(models.Model): subgroup = models.CharField(max_length=1, verbose_name="sous-groupe", null=True) td = models.IntegerField(verbose_name="groupe de TD", null=True) tp = models.IntegerField(verbose_name="groupe de TP", null=True) - parent_group = models.ForeignKey("self", verbose_name="groupe parent", null=True, default=None, related_name="children") + parent = models.ForeignKey("self", verbose_name="groupe parent", null=True, default=None, related_name="children") slug = models.SlugField(max_length=64, default="") @@ -92,18 +92,6 @@ 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() |