$npx skillfedfor your agent

rest-framework-generic-relations

Generic Relations for Django Rest Framework

With conditionsPyPI Dynamic ContentReleased Mar 2024123.6K downloads / mopermissive licensePure Python

Decision gist · record as of 2026-08-14

pure-Python wheel — rest_framework_generic_relations-2.2.0-py3-none-any.whl
v2.2.0 · released 2024-03-27 · Python >=3.8 · 1 runtime deps: djangorestframework

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

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.
Same gist for agents: .md · .json

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.

With conditions

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

Licensepermissive license permissive
Python supportSupports the current Python release >=3.8
Install frictionLow. Pure-Python wheel
Runtime dependencies
1 package
djangorestframework
MaintenanceDormant 870 days since the last release
Last repo commit
First released
Downloads123,619 / month, #11,903 on PyPI 30-day window, as of 2026-08-14
Known vulnerabilitiesNone 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

Capabilities
django generic foreign key serializerrest framework polymorphic relationsdjango rest framework generic relationsserialize generic foreign keys drfpolymorphic model serialization djangogeneric relation serializer
Topics
django-rest-frameworkserializationpolymorphic-relations

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”

Give your agent the search over MCP, or paste the wish link into any chat.

More Dynamic Content packages

MarkupSafe Worth it
PyPI · Dynamic Content · released Sep 2025

MarkupSafe provides a text object that escapes special characters so untrusted strings can be safely embedded in HTML and XML without injection attacks.

BSD-3-Clausecompiled wheel · 3.9+aging
797.1Mdownloads / mo
Jinja2 Worth it
PyPI · Dynamic Content · released Mar 2025

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.

BSD-3-Clausepure Python · 3.7+aging
718.6Mdownloads / mo
soupsieve Worth it
PyPI · Python Modules · released Aug 2026

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.

MITpure Python · 3.10+
428.6Mdownloads / mo
Werkzeug Worth it
PyPI · Application Frameworks · released Apr 2026

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.

BSD-3-Clausepure Python · 3.9+
268.1Mdownloads / mo
Flask Worth it
PyPI · Application Frameworks · released Feb 2026

Flask is a lightweight WSGI web application framework for building web applications in Python, from simple single-page sites to complex multi-route applications.

BSD-3-Clausepure Python · 3.9+
211.4Mdownloads / mo
Mako Worth it
PyPI · Dynamic Content · released Aug 2026

Mako compiles Python-embedded templates into Python modules for fast rendering, supporting layout inheritance, custom functions, and direct Python expressions within template syntax.

MITpure Python · 3.10+
201.7Mdownloads / mo

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