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
Query by active lang #39
Comments
LocalizedField is HStoreField with language codes as keys:
See HStoreField Key lookups on Django Docs |
Oops, am re-read the question. Seems currently is no way to do this. |
Hey @brahica, I would argue that's a bad design. "Active language" is an implicit thread-local state which is most often set during the request handling, so it's best to keep it contained in your views and templates. Lookup like that will break in unexpected ways if you use it in Celery or management tasks. |
@si14 I guess the problem you mention we already have as localized fields depend on thread local state e.g. when calling This said I would love to see such a feature as well. |
As I needed this I have created following search lookup snippet for localized fields in my projects. Potentially can be used as an example to implement other lookups as well. from django.contrib.postgres.fields.hstore import KeyTransform
from django.contrib.postgres.search import (SearchVector, SearchVectorExact,
SearchVectorField)
from django.utils import translation
from localized_fields.fields import LocalizedField
class LocalizedSearchLookup(SearchVectorExact):
lookup_name = 'search'
def process_lhs(self, qn, connection):
if not isinstance(self.lhs.output_field, SearchVectorField):
self.lhs = SearchVector(
KeyTransform(translation.get_language(), self.lhs)
)
return super().process_lhs(qn, connection)
def get_prep_lookup(self):
return str(self.rhs)
LocalizedField.register_lookup(LocalizedSearchLookup) |
Hi,
Just asking, there is a ways filtring by active lang like :
Thx ;)
The text was updated successfully, but these errors were encountered: