Upgrade to Pro — share decks privately, control downloads, hide ads and more …

django-parler - DjangoCon EU 2014 lightning talk

django-parler - DjangoCon EU 2014 lightning talk

Extended version of my previous django-parler presentation. Explain why django-modeltranslation or django-hvad were nog used, and what complex inheritance I'd faced. Now features such as:

* Python 3 support
* Prefetching translations
* Caching
* High-level features such as `{% get_translated_url %}`.
* Admin inlines

Easily translate cheese omelet into omelette du fromage.

Diederik van der Boor

May 15, 2014
Tweet

More Decks by Diederik van der Boor

Other Decks in Programming

Transcript

  1. django-parler
    Easily translate cheese omelet into omelette du fromage.
    Diederik van der Boor Django Meetup 14-05-2014

    View Slide

  2. Simple Django model translations
    without nasty hacks
    with nice admin integration.

    View Slide

  3. Got hopeful
    Making a CMS multilingual:
    Well, let's use something existing...

    View Slide

  4. django-modeltranslation :-(

    View Slide

  5. django-hvad :-(
    Very nice admin, awesome API – however:
    Overrides just about all ORM methods!
    Lots of metaclass magic
    Mixing translated with untranslated objects = hard
    Can't be combined with other apps
    (mptt, polymorphic, shop)
    Doesn't call super() often

    View Slide

  6. django-polymorphic-tree
    Yes, we do crazy things...

    View Slide

  7. django-fluent CMS
    ...when they make sense

    View Slide

  8. 1 row for each language

    View Slide

  9. Let's just do this..!

    View Slide

  10. And tried more hacking!

    View Slide

  11. Package that!
    So we:
    – Hacked something directly in the CMS app
    – K.I.S.S
    – Manually created translated fields table
    – Manually assigned descriptors
    – Hey that works!!

    View Slide

  12. Model API

    View Slide

  13. Usage

    View Slide

  14. Features
    Python 3
    qs.translated(''en'', name=''foo'')
    qs.prefetch_related(''translations'')
    {% get_translated_url ''fr'' page as url %}
    caching individual objects
    admin tabs + inlines

    View Slide

  15. View Slide

  16. View Slide

  17. View Slide

  18. Thanks to caching...

    View Slide

  19. View Slide

  20. View Slide

  21. @vdboor @edoburu
    pip install 'django-parler>=1.0b2'
    https://github.com/edoburu/django-parler
    http://django-fluent.org

    View Slide