Django REST Multiple Models

raw JSON →
2.1.3 verified Fri May 01 auth: no python

Provides a generic view (and mixin) for returning multiple models or querysets from a single Django REST Framework endpoint. Current version 2.1.3. Maintenance appears sporadic.

pip install django-rest-multiple-models
error ModuleNotFoundError: No module named 'drf_multiple_model'
cause Package not installed or installed under a different name.
fix
Run 'pip install django-rest-multiple-models' and verify installation.
error AttributeError: module 'drf_multiple_model.views' has no attribute 'MultipleModelAPIView'
cause Upgraded from v1.x to v2.x without updating import.
fix
Use 'ObjectMultipleModelAPIView' instead.
error ImproperlyConfigured: Each item in querylist must have 'queryset' and 'serializer_class' keys.
cause Missing required keys in querylist dict.
fix
Ensure each dict contains 'queryset' and 'serializer_class'.
error AssertionError: Expected view to have attribute 'sort_fn' or 'sort_field' if 'sort_url_param' is set.
cause Trying to use sorting without defining sorting logic.
fix
Set 'sort_fn' or 'sort_field' on the view when using 'sort_url_param'.
breaking v2.0 renamed MultipleModelAPIView to ObjectMultipleModelAPIView, and removed the old mixin-based API. Update imports accordingly.
fix Replace 'MultipleModelAPIView' with 'ObjectMultipleModelAPIView'. See changelog for full migration.
breaking Pagination in v2.0 changed from a global setting to a per-querylist attribute. The old 'pagination_count' attribute is removed.
fix Set 'pagination' inside each querylist dict (or use class-level 'pagination'). See docs.
gotcha The 'flat' property (FlatMultipleModelAPIView) returns all items in a single list. Without 'flat', each label is a key with a list. Ensure client expectations match.
fix Use 'FlatMultipleModelAPIView' when a flat list is desired.

Define a view that returns multiple querysets grouped by label or flat.

# views.py
from drf_multiple_model.views import ObjectMultipleModelAPIView
from .models import Author, Book
from .serializers import AuthorSerializer, BookSerializer

class MixedAPIView(ObjectMultipleModelAPIView):
    querylist = [
        {'queryset': Author.objects.all(), 'serializer_class': AuthorSerializer},
        {'queryset': Book.objects.all(), 'serializer_class': BookSerializer, 'label': 'books'},
    ]
    # Optional: sorting, pagination, etc.