diff --git a/apps/course/models.py b/apps/course/models.py index b03092b6..10175b21 100644 --- a/apps/course/models.py +++ b/apps/course/models.py @@ -75,9 +75,15 @@ class Course(models.Model): update_at = models.DateTimeField(auto_now=True) def save(self, *args, **kwargs): - print(self.title) - self.slug = slugify(self.title[:100] + '_' + str(uuid4())[:6], allow_unicode=True) - print(self.slug) + if not self.slug: + self.slug = slugify( + self.title[:100], + allow_unicode=True + ) + + if Course.objects.filter(slug=self.slug).exists(): + self.slug += '_' + str(uuid4())[:6] + return super().save() @property