Comments (3)
name
should actually be field_name
:
class CompetitionFilter(FilterSet):
from_achievement_date = DateTimeFilter(
field_name='distance_achievement_date', lookup_expr='gte')
to_achievement_date = DateTimeFilter(
field_name='distance_achievement_date', lookup_expr='lte')
min_distance_in_feet = NumberFilter(
field_name='distance_in_feet', lookup_expr='gte')
max_distance_in_feet = NumberFilter(
field_name='distance_in_feet', lookup_expr='lte')
drone_name = AllValuesFilter(
field_name='drone__name')
pilot_name = AllValuesFilter(
field_name='pilot__name')
class Meta:
model = Competition
fields = (
'distance_in_feet',
'from_achievement_date',
'to_achievement_date',
'min_distance_in_feet',
'max_distance_in_feet',
# drone__name will be accessed as drone_name
'drone_name',
# pilot__name will be accessed as pilot_name
'pilot_name',
)
but also see #3 because the FilterSet
import needs to come from django_filters
, not rest_framework
from django-restful-web-services.
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.
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.