rest-framework-generic-relations
Generic Relations for Django Rest Framework
Decision gist · record as of 2026-08-14
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.AI-flagged interpretation of the facts on this page — verify before relying
Before you install
- Requires Django 3.2+, Django REST Framework 3.12+, and Python 3.8+.
- You must add the package to INSTALLED_APPS.
- Low friction install with a single runtime dependency on djangorestframework.
License · maintenance · safety
permissive license (permissive) — Licensed under BSD (permissive), so you can use, modify, and distribute freely with minimal restrictions.
last release 2024-03-27 (870 days) · last repo commit 2024-03-27 · 7 stars
0 known vulnerabilities (OSV.dev, 2026-08-14) · 123,619 downloads/mo, #11,903 on PyPI
Alternatives
Verify before relying
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')- 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.
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 on this page. Verify before relying on it.
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
rest-framework-generic-relations on PyPI
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.
Requires Django 3.2+, Django REST Framework 3.12+, and Python 3.8+. You must add the package to INSTALLED_APPS.
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')
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 | permissive license permissive |
| Python support | Supports the current Python release >=3.8 |
| Install friction | Low. Pure-Python wheel |
| Runtime dependencies | 1 packagedjangorestframework |
| Maintenance | Dormant 870 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 123,619 / month, #11,903 on PyPI 30-day window, as of 2026-08-14 |
| Known vulnerabilities | None known OSV.dev, checked 2026-08-14 |
| Classifiers | Environment :: Web EnvironmentFramework :: DjangoFramework :: Django :: 3.2Framework :: Django :: 4.2Framework :: Django :: 5.0Intended Audience :: DevelopersLicense :: OSI Approved :: BSD LicenseOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Programming Language :: Python :: Implementation :: CPythonProgramming Language :: Python :: Implementation :: PyPy |
Evidence: rest_framework_generic_relations-2.2.0-py3-none-any.whl
Tags
Let your AI agent find packages like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 14,416 PyPI packages by what they can do, searchable in plain language.
wish › “django generic foreign key serializer”
- rest-framework-generic-relationsProvides Django REST Framework serializers that handle Django's…
- drf-writable-nestedExtends Django REST Framework serializers to handle creation and…
- djangorestframework-bulkAdds bulk create, update, and delete operations to Django REST…
Give your agent the search over MCP, or paste the wish link into any chat.
More Dynamic Content packages
MarkupSafe provides a text object that escapes special characters so untrusted strings can be safely embedded in HTML and XML without injection attacks.
Jinja2 is a templating engine that renders dynamic content by combining templates with Python-like syntax and data, supporting template inheritance, macros, autoescaping, and sandboxed execution.
Soupsieve is a CSS selector library designed to work with Beautiful Soup 4 to select, match, and filter HTML and XML elements using modern CSS selectors from CSS level 1 through CSS level 4 specifications.
Install it if you use Beautiful Soup for HTML or XML parsing and want modern CSS selector support.
Werkzeug is a WSGI utility library providing request/response objects, URL routing, an interactive debugger, HTTP utilities, and a development server for building web applications.
Flask is a lightweight WSGI web application framework for building web applications in Python, from simple single-page sites to complex multi-route applications.
Mako compiles Python-embedded templates into Python modules for fast rendering, supporting layout inheritance, custom functions, and direct Python expressions within template syntax.
See also drf-writable-nested · django-rest-polymorphic · drf-rw-serializers · django-modelcluster · swapper · drf-extra-fields · drf-dynamic-fields · django-rest-multiple-models · djangorestframework-dataclasses · djangorestframework-bulk