docs: def get_uniqueness_lookups(field, instance, unique_with):
      """
      Returns a dict'able tuple of lookups to ensure uniqueness of a slug.
      """
      for original_lookup_name in unique_with:
          if '__' in original_lookup_name:
              field_name, inner_lookup = original_lookup_name.split('__', 1)
          else:
              field_name, inner_lookup = original_lookup_name, None
  
          try:
              other_field = instance._meta.get_field(field_name)
          except FieldDoesNotExist:
              raise ValueError('Could not find attribute %s.%s referenced'
                               ' by %s.%s (see constraint `unique_with`)'
                               % (instance._meta.object_name, field_name,
                                  instance._meta.object_name, field.name))
  
          if field == other_field:
              raise ValueError('Attribute %s.%s references itself in `unique_with`.'
                               ' Please use "unique=True" for this case.'
                               % (instance._meta.object_name, field_name))
  
          value = getattr(instance, field_name)
          if not value:
              if other_field.blank:
                  field_object = instance._meta.get_field(field_name)
                  if isinstance(field_object, ForeignKey):
                      lookup = '%s__isnull' % field_name
                      yield lookup, True
                  break
              raise ValueError('Could not check uniqueness of %s.%s with'
                               ' respect to %s.%s because the latter is empty.'
                               ' Please ensure that "%s" is declared *after*'
                               ' all fields listed in unique_with.'
                               % (instance._meta.object_name, field.name,
                                  instance._meta.object_name, field_name,
                                  field.name))
          if isinstance(other_field, DateField):    # DateTimeField is a DateField subclass
              inner_lookup = inner_lookup or 'day'
  
              if '__' in inner_lookup:
                  raise ValueError('The `unique_with` constraint in %s.%s'
                                   ' is set to "%s", but AutoSlugField only'
                                   ' accepts one level of nesting for dates'
                                   ' (e.g. "date__month").'
                                   % (instance._meta.object_name, field.name,
                                      original_lookup_name))
  
              parts = ['year', 'month', 'day']
              try:
                  granularity = parts.index(inner_lookup) + 1
              except ValueError:
                  raise ValueError('expected one of %s, got "%s" in "%s"'
                                      % (parts, inner_lookup, original_lookup_name))
              else:
                  for part in parts[:granularity]:
                      lookup = '%s__%s' % (field_name, part)
                      yield lookup, getattr(value, part)
          else:
              # TODO: this part should be documented as it involves recursion
              if inner_lookup:
                  if not hasattr(value, '_meta'):
                      raise ValueError('Could not resolve lookup "%s" in `unique_with` of %s.%s'
                                       % (original_lookup_name, instance._meta.object_name, field.name))
                  for inner_name, inner_value in get_uniqueness_lookups(field, value, [inner_lookup]):
                      yield original_lookup_name, inner_value
              else:
                  yield field_name, value