-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for namespaces in APIRoot.
- Loading branch information
Rocky Meza
committed
Dec 25, 2014
1 parent
e6041f9
commit eb0b5ca
Showing
3 changed files
with
62 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from django.conf.urls import url, include | ||
from django.db import models | ||
|
||
from rest_framework import serializers, viewsets, routers | ||
|
||
|
||
class NamespacedRouterTestModel(models.Model): | ||
uuid = models.CharField(max_length=20) | ||
text = models.CharField(max_length=200) | ||
|
||
|
||
class NoteSerializer(serializers.HyperlinkedModelSerializer): | ||
url = serializers.HyperlinkedIdentityField(view_name='api-namespace:routertestmodel-detail', lookup_field='uuid') | ||
|
||
class Meta: | ||
model = NamespacedRouterTestModel | ||
fields = ('url', 'uuid', 'text') | ||
|
||
|
||
class NoteViewSet(viewsets.ModelViewSet): | ||
queryset = NamespacedRouterTestModel.objects.all() | ||
serializer_class = NoteSerializer | ||
lookup_field = 'uuid' | ||
|
||
router = routers.DefaultRouter() | ||
|
||
router.register(r'note', NoteViewSet) | ||
|
||
|
||
urlpatterns = [ | ||
url('^namespaced-api/', include(router.urls, namespace='api-namespace')), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters