Many broken things
This commit is contained in:
0
passbook/admin/api/v1/__init__.py
Normal file
0
passbook/admin/api/v1/__init__.py
Normal file
8
passbook/admin/api/v1/routers.py
Normal file
8
passbook/admin/api/v1/routers.py
Normal file
@ -0,0 +1,8 @@
|
||||
# from django.conf.urls import url, include
|
||||
|
||||
# # Add this!
|
||||
# from passbook.admin.api.v1.source import SourceResource
|
||||
|
||||
# urlpatterns = [
|
||||
# url(r'source/', include(SourceResource.urls())),
|
||||
# ]
|
26
passbook/admin/api/v1/source.py
Normal file
26
passbook/admin/api/v1/source.py
Normal file
@ -0,0 +1,26 @@
|
||||
# from rest_framework.serializers import HyperlinkedModelSerializer
|
||||
# from passbook.admin.api.v1.utils import LookupSerializer
|
||||
# from passbook.core.models import Source
|
||||
# from passbook.oauth_client.models import OAuthSource
|
||||
|
||||
# from rest_framework.viewsets import ModelViewSet
|
||||
|
||||
# class LookupSourceSerializer(HyperlinkedModelSerializer):
|
||||
|
||||
# def to_representation(self, instance):
|
||||
# if isinstance(instance, Source):
|
||||
# return SourceSerializer(instance=instance).data
|
||||
# elif isinstance(instance, OAuthSource):
|
||||
# return OAuthSourceSerializer(instance=instance).data
|
||||
# else:
|
||||
# return LookupSourceSerializer(instance=instance).data
|
||||
|
||||
# class Meta:
|
||||
# model = Source
|
||||
# fields = '__all__'
|
||||
|
||||
|
||||
# class SourceViewSet(ModelViewSet):
|
||||
|
||||
# serializer_class = LookupSourceSerializer
|
||||
# queryset = Source.objects.select_subclasses()
|
17
passbook/admin/api/v1/utils.py
Normal file
17
passbook/admin/api/v1/utils.py
Normal file
@ -0,0 +1,17 @@
|
||||
from django.db.models import Model
|
||||
from rest_framework.serializers import ModelSerializer
|
||||
|
||||
|
||||
class LookupSerializer(ModelSerializer):
|
||||
|
||||
mapping = {}
|
||||
|
||||
def to_representation(self, instance):
|
||||
for __model, __serializer in self.mapping.items():
|
||||
if isinstance(instance, __model):
|
||||
return __serializer(instance=instance).to_representation(instance)
|
||||
raise KeyError(instance.__class__.__name__)
|
||||
|
||||
class Meta:
|
||||
model = Model
|
||||
fields = '__all__'
|
Reference in New Issue
Block a user