Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why is USE_DEFAULT_QUERYSET inverted? #355

Open
ThibaultLemaire opened this issue Nov 9, 2018 · 1 comment
Open

Why is USE_DEFAULT_QUERYSET inverted? #355

ThibaultLemaire opened this issue Nov 9, 2018 · 1 comment

Comments

@ThibaultLemaire
Copy link

When I read USE_DEFAULT_QUERYSET, I understand "Use Django's default queryset? Yes/No".

So when I set it to True to tell hvad to use a translation-aware queryset, it doesn't make sense to me.

I would either rename it to something more explicit like USE_TRANSLATION_AWARE_QUERYSET, or invert it.

Also, why is it off by default? Of course I want translation-aware querysets, otherwise I wouldn't have installed hvad.

@spectras
Copy link
Collaborator

spectras commented Nov 9, 2018

Hello,

Django has a feature they call the “default manager” that creates the “default queryset”.

Thus, the setting is so named because it instructs hvad to use that feature to set itself to provide the default queryset for translated models. Maybe not the best name ever, but changing it now would break all projects using it, so it's there to stay.

It is not enabled by default, because it is incompatible with some third-party apps and addons. Hvad tends to lean towards safe defaults.

As a reminder, when you have a translatable model, there are three ways to get a queryset from the hvad's manager:

MyModel.objects.language()      # always translation aware
MyModel.objects.get_queryset()  # default queryset. Hvad-enabled if USE_DEFAULT_QUERYSET.
MyModel.objects.untranslated()  # never translation aware

All direct uses of queryset methods (filter, order_by, ...) are forwarded to .get_queryset().method().

Translation-aware apps should always use .language() or .untranslated().
Translation-unaware apps will use the usual API, which means they will use get_queryset(). USE_DEFAULT_QUERYSET makes it possible to choose whether that will be the same as language() or the same as untranslated().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants