Queryset API

TranslationQueryset

This is the queryset used by the nani.manager.TranslationManager.

Performance consideration

While most methods on nani.manager.TranslationQueryset querysets run using the same amount of queries as if they were untranslated, they all do slightly more complex queries (one extra join).

The following methods run two queries where standard querysets would run one:

New methods

Methods described here are unique to django-nani and cannot be used on normal querysets.

language

language(language_code=None)

Sets the language for the queryset to either the language code defined or the currently active language. This method should be used for all queries for which you want to have access to all fields on your model.

untranslated

untranslated()

Returns a nani.manager.FallbackQueryset instance which by default does not fetch any translations. This is useful if you want a list of Shared Model instances, regardless of whether they’re translated in any language.

Note

No translated fields can be used in any method of the queryset returned my this method. See FallbackQueryset

Note

This method is only available on the manager directly, not on a queryset.

delete_translations

delete_translations()

Deletes all Translations Model instances in a queryset, without deleting the Shared Model instances.

Not implemented public queryset methods

The following are methods on a queryset which are public APIs in Django, but are not implemented (yet) in django-nani:

Using any of these methods will raise a NotImplementedError.

FallbackQueryset

This is a queryset returned by untranslated, which can be used both to get the untranslated parts of models only or to use fallbacks. By default, only the untranslated parts of models are retrieved from the database.

Warning

You may not use any translated fields in any method on this queryset class.

New Methods

use_fallbacks

use_fallbacks(*fallbacks)

Returns a queryset which will use fallbacks to get the translated part of the instances returned by this queryset. If fallbacks is given as a tuple of language codes, it will try to get the translations in the order specified. Otherwise the order of your LANGUAGES setting will be used.

Warning

Using fallbacks will cause a lot of queries! In the worst case 1 + (n * x) with n being the amount of rows being fetched and x the amount of languages given as fallbacks. Only ever use this method when absolutely necessary and on a queryset with as few results as possibel.

Project Versions

Table Of Contents

Previous topic

Models

Next topic

Forms

This Page