--- id: rest-framework-generic-relations version: "2.2.0" license: unclear license_treatment: permissive maintenance: dormant --- # rest-framework-generic-relations — Generic Relations for Django Rest Framework License: permissive · Maintenance: dormant · Downloads: 123.6K/mo ## What it is and what it does This package extends Django REST Framework with serializers for handling generic foreign keys—the polymorphic relationships Django allows via ContentType and object_id pairs. It provides two main components: one maps model types to their respective serializers for serializing a single generic relationship to any of several possible models, and another handles serializing mixed lists of different model instances, delegating to the appropriate serializer based on each object's type. The library is designed for scenarios where a single model field points to multiple unrelated model types. It handles both read and write operations, though write support relies on the nested serializers' ability to deserialize. The package is stable and maintained for bug fixes and compatibility updates, though no major feature development is planned. Use it for: - Tag or annotation systems where tags can be attached to multiple unrelated model types. - Activity feeds or audit logs that record actions on different model types in a single list. - API endpoints returning mixed collections of different model types. - Polymorphic relationships where a single foreign key field must point to one of several model types. ## Worth the install? AI-flagged interpretation of the facts above — verify before relying. Provides Django REST Framework serializers that handle Django's generic foreign keys, allowing you to serialize and deserialize polymorphic relationships across arbitrary model types. Yes, if you need to serialize Django generic foreign keys in REST APIs. The package is well-suited for its narrow purpose, has no known vulnerabilities, low install friction, and permissive licensing. The dormant maintenance status is not a concern for a stable, focused library—it indicates the maintainer will fix bugs and keep compatibility current rather than add new features. Use it when your API design genuinely requires polymorphic relations. ## Install pip install rest-framework-generic-relations uv add rest-framework-generic-relations poetry add rest-framework-generic-relations ## Installing rest-framework-generic-relations Before you install: Low friction install with a single runtime dependency on djangorestframework. Maintenance is dormant—the maintainer explicitly states no major changes are planned, though reported bugs are addressed and compatibility is kept current with recent Python and Django versions. License in practice: Licensed under BSD (permissive), so you can use, modify, and distribute freely with minimal restrictions. Quickstart: pip install rest-framework-generic-relations # In Django settings.py INSTALLED_APPS = ( ..., 'rest_framework_generic_relations', ) # In your serializer from rest_framework_generic_relations.relations import GenericRelatedField class TagSerializer(serializers.ModelSerializer): tagged_object = GenericRelatedField({ Bookmark: BookmarkSerializer(), Note: NoteSerializer() }) class Meta: model = TaggedItem fields = ('tag_name', 'tagged_object') Requires Django 3.2+, Django REST Framework 3.12+, and Python 3.8+. You must add the package to INSTALLED_APPS. Verify before relying: - Whether write support for generic foreign keys works reliably with custom deserializer logic beyond HyperlinkedRelatedField. - Performance characteristics when serializing large lists of mixed model types. ## Package facts - License: not declared (permissive) - Python support: supports_current - Install friction: low - Maintenance: dormant - Downloads: 123.6K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags django generic foreign key serializer, rest framework polymorphic relations, django rest framework generic relations, serialize generic foreign keys drf, polymorphic model serialization django, generic relation serializer, django-rest-framework, serialization, polymorphic-relations [View on SkillFed](https://skillfed.io/packages/rest-framework-generic-relations) · [View on PyPI](https://pypi.org/project/rest-framework-generic-relations/)