-
Notifications
You must be signed in to change notification settings - Fork 127
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
django-hvad compatibility with FilterSet of Django Rest Framework #340
Comments
Hello, It is because the queryset's actual model is the translation model. It's normal and expected, and works fine everywhere as it behaves exactly like the original model, translations on top of it. However, django filter backend actively tests the model, and bails out. So I'd say it is not a hvad+DRF issue, but actually a hvad+django-filter issue. |
Hello, @spectras, django-hvad supports for rest_framework_filters+hvad ? |
There is no official support. Unfortunately, there are so many third party packages that officially supporting more than one or two would be too much work. It is worth noting rest_framework_filters is based on django-filters, so it's likely to encounter the same issue. On the positive side, that means making either work should make the other work as well. I believe the next iteration of django-hvad should work better with queryset-handling modules, because the queryset's model will be the base model and no longer the automatic translations model. That means modules which explicitly check I didn't try it, but a common workaround for dealing with cases such as django-filter is to: => Pass the translation model when they want the model. For instance, the following is worth trying: class RestaurantFilters(FilterSet):
category = CharFilter(name='master__category', lookup_expr='exact')
class Meta:
model = Restaurant._meta.translations_model Depending on how the 3rd-party package works, this might yield expected results, or this might require some additional filtering (typically on language_code), or this might not work. The better way would be to create a new |
Thank you, I will try it! |
Hi
I have an issue when I implement a filter on my ViewSet.. maybe it's something silly but I really don't know.
My ViewSet
class RestaurantViewSet(viewsets.ModelViewSet):
queryset = Restaurant.objects.language().all()
serializer_class = RestaurantSerializer
permission_classes = (permissions.AllowAny, )
filter_backends = (filters.DjangoFilterBackend,)
filter_class = RestaurantFilters
lookup_field = 'slug'
pagination_class = StandardResultsSetPagination
my filter:
class RestaurantFilters(FilterSet):
category = CharFilter(name='category', lookup_expr='exact')
I think it has to do with something wrong on the get_queryset method.
If someone has implemented something seemed to please help me
The text was updated successfully, but these errors were encountered: