django-querysetsequence adds helpers for treating multiple disparate
obejcts as a single
QuerySet. This is useful for passing into APIs that only
accepted a single
QuerySetSequence wrapper is used to combine multiple
QuerySetSequence aims to provide the same behavior as Django's
but applied across multiple
- Methods that take a list of fields (e.g.
order_by()) must use fields that are common across all sub-
- Relationships across related models work (e.g.
- The sub-
QuerySetsare evaluated as late as possible (e.g. during iteration, slicing, pickling,
QuerySetAPI methods that are untested/unimplemented raise
Install the package using pip.
pip install --upgrade django-querysetsequence
# Import QuerySetSequence from queryset_sequence import QuerySetSequence # Create QuerySets you want to chain. from .models import SomeModel, OtherModel # Chain them together. query = QuerySetSequence(SomeModel.objects.all(), OtherModel.objects.all()) # Use query as if it were a QuerySet! E.g. in a ListView.
django-querysetsequence is released under the ISC license, its documentation lives on Read the Docs, the code on GitHub, and the latest release on PyPI. It supports Python 3.7+, Django 3.2/4.0/4.1, and is optionally compatible with Django REST Framework 3.11+.
Some ways that you can contribute:
- Check for open issues or open a fresh issue to start a discussion around a feature idea or a bug.
- Fork the repository on GitHub to start making your changes.
- Write a test which shows that the bug was fixed or that the feature works as expected.
- Send a pull request and bug the maintainer until it gets merged and published.