File: slugs.rst

package info (click to toggle)
python-django-parler 2.3-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,032 kB
  • sloc: python: 4,293; makefile: 164; sh: 6
file content (19 lines) | stat: -rw-r--r-- 751 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Using translated slugs in views
===============================

To handle translatable slugs in the :class:`~django.views.generic.detail.DetailView`,
the :class:`~parler.views.TranslatableSlugMixin` can be used to make this work smoothly.
For example:

.. code-block:: python

    class ArticleDetailView(TranslatableSlugMixin, DetailView):
        model = Article
        template_name = 'article/details.html'

The :class:`~parler.views.TranslatableSlugMixin` makes sure that:

* The object is fetched in the proper translation.
* The slug field is read from the translation model, instead of the shared model.
* Fallback languages are handled.
* Objects are not accidentally displayed in their fallback slugs, but redirect to the translated slug.