misses superclass/subclass rivals
When using a superclass/subclass model structure and autoslugs, the utils.generate_unique_slug can miss rivals, and thus generate duplicate slugs. The situtation is: {{{ #!python class Data(models.Model): title = models.CharField(max_length=10) slug = AutoSlugField(populate_from=title) class DataA(Data): pass class DataB(Data): pass
a = DataA(title="foo") b = DataB(title="foo") }}}
After this, there are to Data objects with slug=="foo".
My hack of a solution (just to get things working for me) was to assert what model I wanted to search (self.autoslug_model = Data) and then have utils.generate_unique_slug honour that by finding rivals like this: {{{ if hasattr(instance, 'autoslug_model'): assert isinstance(instance, instance.autoslug_model) ModelClass = instance.autoslug_model else: ModelClass = type(instance) rivals = ModelClass.objects.filter(**lookups).exclude(pk=instance.pk) }}} That's probably not the way to fix it, but it's a bug either way.
Comments (2)
-
-
repo owner - changed status to resolved
I guess we can close the ticket. Feel free to reopen it if I'm wrong.
- Log in to comment
The latest version should handle this. It incorporates a patch that allows you to supply a model manager to use for the lookups. If you specify the model manager from the base class, the slug space will be unique for subclasses.
See http://packages.python.org/django-autoslug/fields.html