Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
happychuks committed Dec 11, 2024
1 parent 6ec47b2 commit 0145b87
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions server/apps/research/models/category.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ class Meta:
verbose_name_plural = 'Categories'

def save(self, *args, **kwargs):
try:
if not self.slug:
self.slug = self.generate_slug()
if len(self.slug) > 255:
raise ValueError("Generated slug exceeds maximum length")
except ValueError as e:
raise ValueError(f"Failed to generate valid slug: {str(e)}")
super().save(*args, **kwargs)
with transaction.atomic():
try:
if not self.slug:
self.slug = self.generate_slug()
if len(self.slug) > 255:
raise ValueError("Generated slug exceeds maximum length")
except ValueError as e:
raise ValueError(f"Failed to generate valid slug") from e
super().save(*args, **kwargs)

def __str__(self):
return self.name
Expand Down

0 comments on commit 0145b87

Please sign in to comment.