def pre_save(self, instance, add: bool):
        """Ran just before the model is saved, allows us to built
        the slug.

        Arguments:
            instance:
                The model that is being saved.

            add:
                Indicates whether this is a new entry
                to the database or an update.

        Returns:
            The localized slug that was generated.
        """

        if not isinstance(instance, AtomicSlugRetryMixin):
            raise ImproperlyConfigured((
                'Model \'%s\' does not inherit from AtomicSlugRetryMixin. '
                'Without this, the LocalizedUniqueSlugField will not work.'
            ) % type(instance).__name__)

        slugs = LocalizedValue()

        for lang_code, value in self._get_populate_values(instance):
            if not value:
                continue

            slug = slugify(value, allow_unicode=True)

            # verify whether it's needed to re-generate a slug,
            # if not, re-use the same slug
            if instance.pk is not None:
                current_slug = getattr(instance, self.name).get(lang_code)
                if current_slug is not None:
                    stripped_slug = current_slug[0:current_slug.rfind('-')]
                    if slug == stripped_slug:
                        slugs.set(lang_code, current_slug)
                        continue

            if self.include_time:
                slug += '-%d' % datetime.now().microsecond

            retries = getattr(instance, 'retries', 0)
            if retries > 0:
                # do not add another - if we already added time
                if not self.include_time:
                    slug += '-'
                slug += '%d' % retries

            slugs.set(lang_code, slug)

        setattr(instance, self.name, slugs)
        return slugs
def pre_save ( self , instance , add : bool ) : if not isinstance ( instance , AtomicSlugRetryMixin ) : raise ImproperlyConfigured ( ( 'Model \'%s\' does not inherit from AtomicSlugRetryMixin. ' 'Without this, the LocalizedUniqueSlugField will not work.' ) % type ( instance ) . __name__ ) slugs = LocalizedValue ( ) for lang_code , value in self . _get_populate_values ( instance ) : if not value : continue slug = slugify ( value , allow_unicode = True ) if instance . pk is not None : current_slug = getattr ( instance , self . name ) . get ( lang_code ) if current_slug is not None : stripped_slug = current_slug [ 0 : current_slug . rfind ( '-' ) ] if slug == stripped_slug : slugs . set ( lang_code , current_slug ) continue if self . include_time : slug += '-%d' % datetime . now ( ) . microsecond retries = getattr ( instance , 'retries' , 0 ) if retries > 0 : if not self . include_time : slug += '-' slug += '%d' % retries slugs . set ( lang_code , slug ) setattr ( instance , self . name , slugs ) return slugs
Ran just before the model is saved, allows us to built
        the slug.

        Arguments:
            instance:
                The model that is being saved.

            add:
                Indicates whether this is a new entry
                to the database or an update.

        Returns:
            The localized slug that was generated.