Skip to content

Added QuerySetSerializer implementation#373

Draft
rhysyngsun wants to merge 8 commits intomainfrom
nl/add_prefetched_serializers
Draft

Added QuerySetSerializer implementation#373
rhysyngsun wants to merge 8 commits intomainfrom
nl/add_prefetched_serializers

Conversation

@rhysyngsun
Copy link
Copy Markdown
Collaborator

@rhysyngsun rhysyngsun commented Dec 10, 2025

What are the relevant tickets?

Part of https://github.com/mitodl/hq/issues/9559

Description (What does it do?)

This adds a ModelSerializer base class that allows serializers to define how data should be fetched for them. An accompanying view is also present that derives the queryset for the view from this. In practice this means that we only need to define our prefetches and annotations once per serializer and the prefetches automatically get picked up. This also gives us free support for varying the queryset based on the serializer returned by get_serializer_class.

In mit-learn we've accomplished a similar mechanism with for_serialization but I ran into limits with this in my work for this issue.

How can this be tested?

Additional Context

@rhysyngsun rhysyngsun force-pushed the nl/add_prefetched_serializers branch from 06096f2 to 42652f0 Compare December 12, 2025 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant