core: make Provider SerializerModel

This commit is contained in:
Jens Langhammer
2020-12-16 21:38:40 +01:00
parent 4d22659b6e
commit 3c12c8b3ff
5 changed files with 43 additions and 3 deletions

View File

@ -14,13 +14,26 @@ class ProviderSerializer(ModelSerializer):
"""Get object type so that we know which API Endpoint to use to get the full object"""
return obj._meta.object_name.lower().replace("provider", "")
def to_representation(self, instance: Provider):
# pyright: reportGeneralTypeIssues=false
if instance.__class__ == Provider:
return super().to_representation(instance)
return instance.serializer(instance=instance).data
class Meta:
model = Provider
fields = ["pk", "name", "authorization_flow", "property_mappings", "__type__"]
fields = [
"pk",
"name",
"application",
"authorization_flow",
"property_mappings",
"__type__",
]
class ProviderViewSet(ReadOnlyModelViewSet):
class ProviderViewSet(ModelViewSet):
"""Provider Viewset"""
queryset = Provider.objects.all()