Comments (9)
Same - the reason is that FilterSet is part of django_filters
, not rest_framekwork
, so:
...
# remove the "from rest_framework import filters" line
...
from django_filters import FilterSet, AllValuesFilter, DateTimeFilter, NumberFilter
...
class CompetitionFilter(FilterSet):
...
from django-restful-web-services.
@deepesh-packt did a PR fix this? If not, this is still going to cause problems for people following along with the text
from django-restful-web-services.
I kept playing until I got the correct references from here:
The correct import in Views.py is like this:
from django_filters import rest_framework as filters
and the code for CompetitionFilter
is like this
min_distance_in_feet = filters.NumberFilter( field_name='distance_in_feet', lookup_expr='gte') max_distance_in_feet = filters.NumberFilter( field_name='distance_in_feet', lookup_expr='lte')
from django-restful-web-services.
I kept playing until I got the correct references from here:
The correct import in Views.py is like this:
from django_filters import rest_framework as filters
and the code for
CompetitionFilter
is like this
min_distance_in_feet = filters.NumberFilter( field_name='distance_in_feet', lookup_expr='gte') max_distance_in_feet = filters.NumberFilter( field_name='distance_in_feet', lookup_expr='lte')
It worked for me! I was using "name" instead of "field_name" which caused the problem.
from django-restful-web-services.
I was having success adapting the contents of the book up to chapter 7, for django 4.1.5 and Python 3.10.6 when I ran into this same problem. I made the adjustments suggested here until my comment, but I see that the CompetitionFilter class is not having an effect, I tried to access the URL: http://localhost:8000/drones/competitions/?pilot_name=Penelope+Pitstop&drone_name=WonderDrone and all competitions are returned.
my code is available at: https://github.com/carlosdelfino/Django-RESTful-Web-Services
from django-restful-web-services.
I found the solution to the problem, follow the path performed:
carlosdelfino/Django-RESTful-Web-Services@76bfbfc
from django-restful-web-services.
If you've forked the repo and updated the code to work, remember to file a PR so that the official repository can be updated, instead of telling people to use your repository.
from django-restful-web-services.
Please, also remember to rename "filter_fields" to "filterset_fields" in the classes with the List suffix (DroneCategoryList, DroneList, and PilotList), else request with filter query parameter will always return list of all the objects.
from django-restful-web-services.
from django_filters import FilterSet, AllValuesFilter, DateTimeFilter, NumberFilter
from django_filters import rest_framework as filters
from django-restful-web-services.
Related Issues (4)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-restful-web-services.