justinmayer / django-autoslug

AutoSlugField for Django. Supports (but not does not require) unidecode/pytils for transliteration. Old issue tracker is at Bitbucket: https://bitbucket.org/neithere/django-autoslug/issues

Home Page:https://readthedocs.org/projects/django-autoslug/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add modeltranslation support

fabiocaccamo opened this issue · comments

Steps to reproduce the problem:

  • more languages, for example: en, it, fr
  • default language: en
  • modeltranslation installed
  • model with a name field and a slug field populated from name
  • name and slug fields are marked for translation in translation.py
  • in the admin populate the name field for all languages using the different values and save it

Current result:
All slug values are always (for all languages) the slugified version of name in the default language:

slug_en populated from name_en
slug_it populated from name_en
slug_fr populated from name_en

Expected result:
Each slug value should be the slugified version of name for the corresponding language:

slug_en populated from name_en
slug_it populated from name_it
slug_fr populated from name_fr

Dirty solution overriding model save method:

#requires always_update = False
def save(self, *args, **kwargs):
    
    for lang_code, lang_verbose in settings.LANGUAGES:
        lang_code = lang_code.replace('-', '_')
        
        setattr(self, 'slug_%s' % lang_code, slugify( getattr(self, 'name_%s' % lang_code, u'') ))
        
    super( NameSlugModel, self ).save( *args, **kwargs )

Check PR #26

Any update about this issue?

+1 It would be really great to have such feature out of the box!!!

@justinmayer @parruc still interested in a PR for this issue?

I have done it the ugly way in the save method so I do not strictly need it but I still think it would be beneficial for the project: urls are often based on slugs and having translated slugs that comes from specific language titles would helps with website positioning and user friendliness of the site IMO.

@parruc I have the impression that this project is a little bit abandoned by the maintainer.