Registry /
web-framework / rest-framework-generic-relations
Install & Compatibility
Where this runs
tested against v2.2.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 70.7MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 3.7s · import 0.000s · 71MB
70MB installed
● package 70MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
GenericRelatedField
✓ from generic_relations.fields import GenericRelatedField
✗ from rest_framework_generic_relations.fields import GenericRelatedField
Define a serializer with a GenericRelatedField that provides different serializers based on the GFK content type.
from rest_framework_generic_relations.fields import GenericRelatedField
from rest_framework import serializers
from myapp.models import Tag, Product, Article
class TaggedItemSerializer(serializers.ModelSerializer):
content_object = GenericRelatedField(
serializer_polymorphic=lambda: {
Product: ProductSerializer,
Article: ArticleSerializer,
}
)
class Meta:
model = Tag
fields = ['id', 'tag', 'content_object']
Upgrade
Version history
2.2.0latest on PyPI · released Mar 27, 2024
Audit
Dependencies
djangorequiredRequired dependency for Django models and GFK
djangorestframeworkrequiredRequired for DRF serializers and views