diff --git a/db/user.py b/db/user.py index d3e1401d..3847ee88 100644 --- a/db/user.py +++ b/db/user.py @@ -46,16 +46,17 @@ def profile_pic(self): path = f'user/profile/{self.id}.png' if fs.exists(path): return f"{decouple_config('BE_DOMAIN_NAME')}{fs.url(path)}" - + def save(self, *args, **kwargs): - full_name = f"{self.first_name}{self.last_name or ''}".replace(" ", "").lower()[:85] - self.muid = f"{full_name}@mulearn" - - counter = 0 - while User.objects.filter(muid=self.muid).exists(): - counter += 1 - self.muid = f"{full_name}-{counter}@mulearn" - + if self.pk is None: + full_name = f"{self.first_name}{self.last_name or ''}".replace(" ", "").lower()[:85] + self.muid = f"{full_name}@mulearn" + + counter = 0 + while User.objects.filter(muid=self.muid).exists(): + counter += 1 + self.muid = f"{full_name}-{counter}@mulearn" + return super().save(*args, **kwargs)