{"library":"rest-framework-generic-relations","title":"Django REST Framework Generic Relations","description":"A Django REST Framework extension providing a GenericRelatedField for serializers to handle generic foreign keys (GFKs). Version 2.2.0 supports Python >=3.8 and DRF >=3.12. Stable, infrequent releases.","language":"python","status":"active","last_verified":"Fri May 01","install":{"commands":["pip install rest-framework-generic-relations"],"cli":null},"imports":["from rest_framework_generic_relations.fields import GenericRelatedField"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"from rest_framework_generic_relations.fields import GenericRelatedField\nfrom rest_framework import serializers\nfrom myapp.models import Tag, Product, Article\n\nclass TaggedItemSerializer(serializers.ModelSerializer):\n    content_object = GenericRelatedField(\n        serializer_polymorphic=lambda: {\n            Product: ProductSerializer,\n            Article: ArticleSerializer,\n        }\n    )\n    class Meta:\n        model = Tag\n        fields = ['id', 'tag', 'content_object']","lang":"python","description":"Define a serializer with a GenericRelatedField that provides different serializers based on the GFK content type.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}