def METHOD_NAME(self, model_instance, add):
    # get fields to populate from and slug field to set
    if not isinstance(self._populate_from, (list, tuple)):
        self._populate_from = (self._populate_from,)
    slug_field = model_instance._meta.get_field(self.attname)
    # only set slug if empty and first-time save, or when overwrite=True
    if add and not getattr(model_instance, self.attname) or self.overwrite:
        # slugify the original field content and set next step to 2
        def slug_for_field(field):
            return self.slugify_func(getattr(model_instance, field))
        slug = self.separator.join(map(slug_for_field, self._populate_from))
        next_num = 2
    else:
        # get slug from the current model instance
        slug = getattr(model_instance, self.attname)
        # model_instance is being modified, and overwrite is False,
        # so instead of doing anything, just return the current slug
        return slug
    # strip slug depending on max_length attribute of the slug field
    # and clean-up
    slug_len = slug_field.max_length
    if slug_len:
        slug = slug[:slug_len]
    slug = self._slug_strip(slug)
    if self.uppercase:
        slug = slug.upper()
    original_slug = slug
    if self.allow_duplicates:
        return slug
    # exclude the current model instance from the queryset used in finding
    # the next valid slug
    queryset = self.get_queryset(model_instance.__class__, slug_field)
    if model_instance.pk:
        queryset = queryset.exclude(pk=model_instance.pk)
    # form a kwarg dict used to impliment any unique_together contraints
    kwargs = {}
    for params in model_instance._meta.unique_together:
        if self.attname in params:
            for param in params:
                kwargs[param] = getattr(model_instance, param, None)
    kwargs[self.attname] = slug
    # increases the number while searching for the next valid slug
    # depending on the given slug, clean-up
    while not slug or queryset.filter(**kwargs):
        slug = original_slug
        end = "%s%s" % (self.separator, next_num)
        end_len = len(end)
        if slug_len and len(slug) + end_len > slug_len:
            slug = slug[: slug_len - end_len]
            slug = self._slug_strip(slug)
        slug = "%s%s" % (slug, end)
        kwargs[self.attname] = slug
        next_num += 1
    return slug