Задать вопрос

Тел: +7 965 3737 888

503

Просмотров

2

Ответов

AutoSlugField and unique_slugify combined

Extra field for slugs that does the work.

If the slug value is given, the value is not recreated but correctness is ensured. If value is not given, the field regenerates the slug.

Вопрос полезен? Да0/Нет0
file_3622.py(4.2Кб)
None

Ответы (2):

Ответptchaw:07.02.2012
Ответ полезен? Да0/Нет0

There's another bug here: the attribute for the field isn't set for the last condition:

return slugify(slug)[:self.max_length]

Changing it to:

slug = slugify(slug)[:self.max_length]
setattr(model_instance, self.attname, slug)
return slug

Will ensure it is set

Ответeternicode:13.10.2010
Ответ полезен? Да0/Нет0

Haven't tested this yet, but one note:

super(fields.SlugField, self).__init__(*args, **kwargs)

Should call super of AutoSlugField:

super(AutoSlugField, self).__init__(*args, **kwargs)