diff options
-rw-r--r-- | models.py | 27 |
1 files changed, 15 insertions, 12 deletions
@@ -28,18 +28,21 @@ class Group(models.Model): return self.name def save(self): - parts = self.name.split("-")[-2:] - group = parts[1].strip()[2:] - - self.mention = parts[0].strip() - self.subgroup = group[0] - - if len(group) > 1: - self.td = int(group[1]) - if len(group) > 2: - self.tp = int(group[2]) - - super(Group, self).save() + try: + parts = self.name.split("-")[-2:] + group = parts[1].strip()[2:] + + self.mention = parts[0].strip() + self.subgroup = group[0] + + if len(group) > 1: + self.td = int(group[1]) + if len(group) > 2: + self.tp = int(group[2]) + except: + print("Malformed name: {0}. Ignoring".format(self.name)) + finally: + super(Group, self).save() class Meta: |