This repository has been archived on 2024-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
authentik/passbook/admin/api/v1/utils.py
2018-11-16 09:10:35 +01:00

18 lines
501 B
Python

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__'