Autoslug tries to populate localized AutoSlugField that is not mark as translatable by modeltranslation
You can see in the following code that the slug is populated from title, which is localized, but the slug itself is NOT localized:
# models.py
class Question(models.Model):
title = models.CharField(max_length=255)
description = models.TextField()
slug = AutoSlugField(populate_from='title', always_update=True, unique=True)
# translation.py
class QTranslation(TranslationOptions):
fields = ('title', 'description')
translator.register(Question, QTranslation)
Now if you try to create a Question, autoslug fails because it tries to get the field slug_en_us
, which does not exist...
Traceback (most recent call last):
File "<console>", line 1, in <module>
File ".../site-packages/django/db/models/base.py", line 589, in save
force_update=force_update, update_fields=update_fields)
File ".../site-packages/django/db/models/base.py", line 626, in save_base
update_fields=update_fields, raw=raw, using=using)
File ".../site-packages/django/dispatch/dispatcher.py", line 198, in send
response = receiver(signal=self, sender=sender, **named)
File ".../site-packages/autoslug/fields.py", line 307, in modeltranslation_update_slugs
field_value = getattr(instance, field_name_localized)
AttributeError: 'Question' object has no attribute 'slug_en_us'
- django 1.7.7
- autoslug 1.8.0
- modeltranslation 0.9.1
Comments (4)
-
-
reporter Hmmm good idea, this way I can use the latest version, thank you :)
-
repo owner - marked as blocker
-
repo owner - changed status to resolved
Seems to be resolved. Will be published as 1.9.
- Log in to comment
I have same issue, Django
1.8.2
, modeltranslation0.9.1
and django-autoslug1.8.0
. As workaround, you can subclassAutoSlugField
: