Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Maxence Bothorel
funkwhale
Commits
bf6fe44b
Verified
Commit
bf6fe44b
authored
Mar 21, 2018
by
Eliot Berriot
Browse files
More filters / ordering option on playlist API
parent
f503466a
Changes
2
Hide whitespace changes
Inline
Side-by-side
api/funkwhale_api/playlists/filters.py
View file @
bf6fe44b
from
django_filters
import
rest_framework
as
filters
from
funkwhale_api.music
import
utils
from
.
import
models
class
PlaylistFilter
(
filters
.
FilterSet
):
q
=
filters
.
CharFilter
(
name
=
'_'
,
method
=
'filter_q'
)
class
Meta
:
model
=
models
.
Playlist
fields
=
{
'user'
:
[
'exact'
],
'name'
:
[
'exact'
,
'icontains'
],
'q'
:
'exact'
,
}
def
filter_q
(
self
,
queryset
,
name
,
value
):
query
=
utils
.
get_query
(
value
,
[
'name'
,
'user__username'
])
return
queryset
.
filter
(
query
)
api/funkwhale_api/playlists/views.py
View file @
bf6fe44b
...
...
@@ -8,15 +8,14 @@ from rest_framework.decorators import detail_route
from
rest_framework.response
import
Response
from
rest_framework.permissions
import
IsAuthenticatedOrReadOnly
from
funkwhale_api.music.models
import
Track
from
funkwhale_api.common
import
permissions
from
funkwhale_api.common
import
fields
from
funkwhale_api.music.models
import
Track
from
.
import
filters
from
.
import
models
from
.
import
serializers
class
PlaylistViewSet
(
mixins
.
RetrieveModelMixin
,
mixins
.
CreateModelMixin
,
...
...
@@ -37,6 +36,7 @@ class PlaylistViewSet(
]
owner_checks
=
[
'write'
]
filter_class
=
filters
.
PlaylistFilter
ordering_fields
=
(
'id'
,
'name'
,
'creation_date'
,
'modification_date'
)
def
get_serializer_class
(
self
):
if
self
.
request
.
method
in
[
'PUT'
,
'PATCH'
,
'DELETE'
,
'POST'
]:
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment