Discussion:
Django Filter
Nirali Supe
2018-07-01 03:44:05 UTC
Permalink
Hello,

class JobsFilter(filters.FilterSet):
class Meta:
model = Jobs
fields = {'id': ['exact', 'lt', 'gt'],
'runs': ['exact', 'in', 'lt', 'gt'],
}
class JobsViewSet(viewsets.ModelViewSet):
"""
List all Entries, or create a new one.
"""
queryset = Jobs.objects.all()
serializer_class = JobsSerializer
filter_backends = (filters.DjangoFilterBackend,)
filter_class = JobsFilter

The following url is working:
http://127.0.0.1:8000/suite-runs-by-job?id__lt=2&runs__gt=30


But I need the url in the following format:
http://127.0.0.1:8000/suite-runs-by-job?id=lt:2&runs=gt:30

Is there a way I can do that?
--
You received this message because you are subscribed to the Google Groups "Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-rest-framework+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Jason
2018-07-01 12:22:33 UTC
Permalink
django filters uses django's lookup format to execute the filtering on the
models. while I suspect what you want can be done, its going to require
you to make your own query parser ad transform it to the format filters
expects for the lookups. Is that really a good way to spend your time?
Post by Nirali Supe
Hello,
model = Jobs
fields = {'id': ['exact', 'lt', 'gt'],
'runs': ['exact', 'in', 'lt', 'gt'],
}
"""
List all Entries, or create a new one.
"""
queryset = Jobs.objects.all()
serializer_class = JobsSerializer
filter_backends = (filters.DjangoFilterBackend,)
filter_class = JobsFilter
http://127.0.0.1:8000/suite-runs-by-job?id__lt=2&runs__gt=30
http://127.0.0.1:8000/suite-runs-by-job?id=lt:2&runs=gt:30
Is there a way I can do that?
--
You received this message because you are subscribed to the Google Groups "Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-rest-framework+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...