forked from ansible/django-ansible-base
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Standard way to link to model with multi-word name
- Loading branch information
1 parent
38338da
commit 9f8d26a
Showing
8 changed files
with
72 additions
and
31 deletions.
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
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,11 @@ | ||
from rest_framework.routers import SimpleRouter | ||
|
||
from test_app import views | ||
|
||
router = SimpleRouter() | ||
|
||
router.register(r'organizations', views.UserViewSet, basename='organization') | ||
router.register(r'teams', views.TeamViewSet, basename='team') | ||
router.register(r'users', views.UserViewSet, basename='user') | ||
# using an intentionally unpredictable basename | ||
router.register(r'encrypted_models', views.EncryptionModelViewSet, basename='encryption_test_model') |
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 |
---|---|---|
@@ -1,18 +1,32 @@ | ||
from rest_framework.serializers import ModelSerializer | ||
|
||
from ansible_base.lib.serializers.common import NamedCommonModelSerializer | ||
from test_app.models import EncryptionModel, User | ||
from test_app import models | ||
|
||
|
||
class EncryptionTestSerializer(NamedCommonModelSerializer): | ||
reverse_url_name = None | ||
class OrganizationSerializer(NamedCommonModelSerializer): | ||
class Meta: | ||
model = models.Organization | ||
fields = '__all__' | ||
|
||
|
||
class TeamSerializer(NamedCommonModelSerializer): | ||
reverse_url_name = 'team-detail' | ||
|
||
class Meta: | ||
model = EncryptionModel | ||
fields = NamedCommonModelSerializer.Meta.fields + [x.name for x in EncryptionModel._meta.concrete_fields] | ||
model = models.Team | ||
fields = '__all__' | ||
|
||
|
||
class UserSerializer(ModelSerializer): | ||
class Meta: | ||
model = User | ||
model = models.User | ||
fields = '__all__' | ||
|
||
|
||
class EncryptionTestSerializer(NamedCommonModelSerializer): | ||
reverse_url_name = None | ||
|
||
class Meta: | ||
model = models.EncryptionModel | ||
fields = NamedCommonModelSerializer.Meta.fields + [x.name for x in models.EncryptionModel._meta.concrete_fields] |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,17 +1,27 @@ | ||
from rest_framework import permissions | ||
from rest_framework.routers import SimpleRouter | ||
from rest_framework.viewsets import ModelViewSet | ||
|
||
from test_app.models import User | ||
from test_app.serializers import UserSerializer | ||
from test_app import serializers | ||
|
||
|
||
class UserViewSet(ModelViewSet): | ||
queryset = User.objects.all() | ||
serializer_class = UserSerializer | ||
class TestAppViewSet(ModelViewSet): | ||
permission_classes = [permissions.IsAuthenticated] | ||
|
||
def get_queryset(self): | ||
return self.serializer_class.Meta.model.objects.all() | ||
|
||
router = SimpleRouter() | ||
|
||
router.register(r'users', UserViewSet) | ||
class OrganizationViewSet(TestAppViewSet): | ||
serializer_class = serializers.OrganizationSerializer | ||
|
||
|
||
class TeamViewSet(TestAppViewSet): | ||
serializer_class = serializers.TeamSerializer | ||
|
||
|
||
class UserViewSet(TestAppViewSet): | ||
serializer_class = serializers.UserSerializer | ||
|
||
|
||
class EncryptionModelViewSet(TestAppViewSet): | ||
serializer_class = serializers.EncryptionTestSerializer |