Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
J
JoinTheCity
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Rafal
JoinTheCity
Commits
e71e0504
Commit
e71e0504
authored
Jan 10, 2016
by
Rafal
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add api filter by tag name
parent
d3900df3
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
2 deletions
+27
-2
urls.py
JoinTheCityREST/JoinTheCityREST/urls.py
+2
-0
views.py
JoinTheCityREST/app/Tag/views.py
+25
-2
No files found.
JoinTheCityREST/JoinTheCityREST/urls.py
View file @
e71e0504
...
...
@@ -25,6 +25,8 @@ router.register(r'user_friendship', user_views.UserFriendshipViewSet)
router
.
register
(
r'user_event_request'
,
user_views
.
UserEventRequestViewSet
)
router
.
register
(
r'user_event'
,
user_views
.
UserEventViewSet
)
router
.
register
(
r'user_api'
,
user_views
.
UserAPIViewSet
)
router
.
register
(
r'tag_api'
,
tag_views
.
TagApiViewSet
)
urlpatterns
=
patterns
(
''
,
...
...
JoinTheCityREST/app/Tag/views.py
View file @
e71e0504
from
rest_framework
import
viewsets
,
permissions
from
app.API.models
import
API
from
app.API.serializers
import
APISerializer
from
app.Tag.models
import
Tag
from
app.Tag.serializers
import
TagSerializer
from
django.shortcuts
import
get_object_or_404
import
rest_framework
from
rest_framework.response
import
Response
class
TagViewSet
(
viewsets
.
ModelViewSet
):
"""
...
...
@@ -10,3 +14,22 @@ class TagViewSet(viewsets.ModelViewSet):
queryset
=
Tag
.
objects
.
all
()
serializer_class
=
TagSerializer
permission_classes
=
(
permissions
.
IsAuthenticatedOrReadOnly
,)
class
TagApiViewSet
(
viewsets
.
ModelViewSet
):
"""
API for articles
"""
queryset
=
Tag
.
objects
.
all
()
serializer_class
=
TagSerializer
permission_classes
=
(
permissions
.
IsAuthenticatedOrReadOnly
,)
def
list
(
self
,
request
,
*
args
,
**
kwargs
):
return
Response
(
status
=
rest_framework
.
status
.
HTTP_400_BAD_REQUEST
,
data
=
{
"Request name of tag! Provide it by '../tag_name/"
})
def
retrieve
(
self
,
request
,
pk
):
tag
=
get_object_or_404
(
self
.
queryset
,
name__iexact
=
pk
)
queryset
=
API
.
objects
.
filter
(
tag
=
tag
)
page
=
self
.
paginate_queryset
(
queryset
)
serializer
=
APISerializer
(
page
,
many
=
True
,
context
=
{
'request'
:
request
})
return
self
.
get_paginated_response
(
serializer
.
data
)
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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