Created
November 21, 2015 16:23
-
-
Save NamPNQ/17a54cb4e85add1e90f8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def save(self, *args, **kwargs): | |
| if not self.id: | |
| max_length = Skill._meta.get_field('slug').max_length | |
| self.slug = orig = slugify(self.title)[:max_length] | |
| for x in itertools.count(1): | |
| if not Skill.objects.filter(slug=self.slug).exists(): | |
| break | |
| # Truncate the original slug dynamically. Minus 1 for the hyphen. | |
| self.slug = "%s-%d" % (orig[:max_length - len(str(x)) - 1], x) | |
| super(Skill, self).save(*args, **kwargs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment