Skip to main content

Parler Tools extracts applicable methods from aldryn-translation-tools to be used without django-cms

models.TranslatedAutoSlugMixin

This is a TranslatableModel mixin that automatically generates a suitable slug for the object on save().

If slug_globally_unique is True, then slugs will be required to be unique across all languages.

If slug_globally_unique is False (default), then the strategy used here is that it is OK for two objects to use the same slug if the slugs are for different languages. So if this were used on a translated Article model, these URLs would be valid:

/en/pain - An article in EN about physical discomfort

/fr/pain - An article in FR about bread

Of course, this means that when resolving an object from its URL, care must be taken to factor in the language segment of the URL too.

When using this mixin, it is important to also set the slug_source_field_name property on the implementing model to the name of the translated field which the slug is to be derived from. If you require more slugs to be derived from multiple fields (translated or otherwise), simply override the method get_slug_source to provide the source string for the slug.

Configuration properties

slug_default

Provide a lazy translated string to use for the default slug should an object not have a source string to derive a slug from.

slug_field_name

Provide the name of the translated field in which generated slug shall be stored.

slug_globally_unique

A boolean flag controlling whether slugs are globally unique, or only unique with each language. Default value is False.

slug_max_length

Declares the max_length of slugs. This defaults to the max_length of the slug_field and is determined via introspection.

slug_separator

This determines the separator used before any index added to the slug. It does not determine the separator used in the slug itself, which is always -. This is only provided for compatibility with the slugify()`` method in aldryn_common, but it is not recommended to be used. Defaults to -.

slug_source_field_name

Provide the name of the translated field to be used for deriving the slug. If more than one field, or other complex sources are required, override the method get_slug_source() instead. Note that if get_slug_source() is overriden, it is recommended to also override get_slug_default().

Public methods

get_slug_default

Naively constructs a translated default slug from the object. For better results, just set the slug_default property on the class to a lazy translated string. Alternatively, override this method if you need to more programmtically determine the default slug.

Example: If your model is “news article” and your source field is “title” this will return “news-article-without-title”.

get_slug_max_length

Accepts an optional parameter idx_len.

Introspects the slug field to determine the maximum length, taking into account a possible separator and up to a [idx_len]-digit number.

get_slug_source

Simply returns the value of the slug source field. Override for more complex situations such as using multiple fields (translated or not) as the source.

Metadata

Release files for django-parler-tools 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-parler-tools 0.5.0
File Size Uploaded Provenance Actions
django-parler-tools-0.5.0.tar.gz 5.8 kB Without provenance Details for django-parler-tools-0.5.0.tar.gz

Release files / django-parler-tools-0.5.0.tar.gz

Download URL django-parler-tools-0.5.0.tar.gz
Size 5.8 kB
Tags Source
SHA-256 checksum
How to use checksums
e6f5a05b242b9a440b903d63f8f4f5a6165f7fc1236b87f4ee3bc482de05e4d4
BLAKE2b-256 checksum
How to use checksums
c0b3da2aa8528598dbbcc3d5afd7a900411372d9ae0cfd081785d07580613ef4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for django-parler-tools 0.5.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.5.0 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page