def unique_slug(self):
        if not getattr(self, "slug"): # if it's already got a slug, do nothing.
            from django.template.defaultfilters import slugify
            if hasattr(self,'get_slug_text') and callable(self.get_slug_text):
                slug_txt = self.get_slug_text()
            elif hasattr(self,'__unicode__'):
                slug_txt = unicode(self)
            elif hasattr(self,'__str__'):
                slug_txt = str(self)
            else:
                return
            original_slug = slugify(slug_txt)
            queryset = self.__class__._default_manager.all()
            if not queryset.filter(slug=original_slug).count():
                setattr(self, "slug", original_slug)
            else:
                slug = ''
                next = 2
                while not slug or queryset.filter(slug=slug).count():
                    slug = original_slug
                    end = '-%s' % next
                    if len(slug) + len(end) > 256:
                        slug = slug[:200-len(end)]
                    slug = '%s%s' % (slug, end)
                    next += 1
                setattr(self, "slug", slug)
Customized unique_slug function
dataset/ETHPy150Open newsapps/django-boundaryservice/boundaryservice/models.py/SluggedModel.unique_slug