diff --git a/_modules/apis_core/generic/serializers.html b/_modules/apis_core/generic/serializers.html index fdb7d03cc..11092dde4 100644 --- a/_modules/apis_core/generic/serializers.html +++ b/_modules/apis_core/generic/serializers.html @@ -89,10 +89,14 @@

Source code for apis_core.generic.serializers

-from django.contrib.contenttypes.models import ContentType
+from django.shortcuts import get_object_or_404
+from django.contrib.contenttypes.models import ContentType
 from rest_framework.serializers import (
     HyperlinkedModelSerializer,
     HyperlinkedRelatedField,
+    Serializer,
+    CharField,
+    IntegerField,
 )
 from rest_framework.reverse import reverse
 
@@ -157,6 +161,23 @@ 

Source code for apis_core.generic.serializers

) return serializer
+ + +
+[docs] +class ContentTypeInstanceSerializer(Serializer): + id = IntegerField(required=True) + content_type = CharField(required=True) + +
+[docs] + def to_internal_value(self, data): + data = super().to_internal_value(data) + app_label, model = data.get("content_type").split(".") + content_type = get_object_or_404(ContentType, app_label=app_label, model=model) + return get_object_or_404(content_type.model_class(), pk=data.get("id"))
+
+
diff --git a/genindex.html b/genindex.html index 7a5bd5824..3086325fb 100644 --- a/genindex.html +++ b/genindex.html @@ -936,10 +936,10 @@

C

  • (class in apis_core.apis_metainfo.serializers)
  • - - +