def post_create_slug(sender, instance, **kwargs):
    """Create a slug on freshly created blog posts"""

    if instance.pk and instance.slug is not None:
            return

    slug = slugify(instance.title)
    try:
        sender.objects.exclude(pk__in=[instance.pk])\
            .get(slug=slug)
        # append random characters and be done with it
        random = generate_random()
        slug = '%s-%s' % (slug, random)
    except (__HOLE__, sender.DoesNotExist):
        pass
    instance.slug = slug
dataset/ETHPy150Open jamiecurle/django-omblog/omblog/listeners.py/post_create_slug