def unique_slug(queryset, slug_field, slug):
 i = 0
 while True:
  if (i > 0):
   if (i > 1):
    slug = slug.rsplit(u'-', 1)[0]
   slug = (u'%s-%s' % (slug, i))
  try:
   queryset.get(**{slug_field: slug})
  except ObjectDoesNotExist:
   break
  i += 1
 return slug

def unique_slug ( queryset , slug_field , slug ) : i = 0 while True : if ( i > 0 ) : if ( i > 1 ) : slug = slug . rsplit ( u'-' , 1 ) [ 0 ] slug = ( u'%s-%s' % ( slug , i ) ) try : queryset . get ( ** { slug_field : slug } ) except ObjectDoesNotExist : break i += 1 return slug
ensures a slug is unique for the given queryset .