misses superclass/subclass rivals

Issue #11 resolved
ggbaker created an issue

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)

  1. Log in to comment