Chain together multiple (disparate) QuerySets to treat them as a single QuerySet.
Project description
django-querysetsequence adds helpers for treating multiple disparate QuerySet obejcts as a single QuerySet. This is useful for passing into APIs that only accepted a single QuerySet.
The QuerySetSequence wrapper is used to combine multiple QuerySet instances.
Overview
QuerySetSequence aims to provide the same behavior as Django’s QuerySets, but applied across multiple QuerySet instances.
Supported features:
Methods that take a list of fields (e.g. filter(), exclude(), get(), order_by()) must use fields that are common across all sub-QuerySets.
Relationships across related models work (e.g. 'foo__bar', 'foo', or 'foo_id'). syntax).
The sub-QuerySets are evaluated as late as possible (e.g. during iteration, slicing, pickling, repr()/len()/list()/bool() calls).
Public QuerySet API methods that are untested/unimplemented raise NotImplementedError.
Getting Started
Install the package using pip.
pip install --upgrade django-querysetsequence
Basic Usage
# 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.
Project Information
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 2.2/3.1/3.2/4.0, and is optionally compatible with Django REST Framework 3.9+.
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for django-querysetsequence-0.16.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | aa274acb20cfd395116213eff982d37dd18342ca3b31f2718554891b614471a2 |
|
MD5 | d87b36ed53c995c35c8a3b7e4ec25efb |
|
BLAKE2b-256 | e189e95c19e16d0cc4125714d34a806862a9a044bac6d8f49f146c05808f6364 |
Hashes for django_querysetsequence-0.16-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 529ade0ed5b6c9a3e70e0c814a70f726f081c60eef59635872dc55c3388e8918 |
|
MD5 | 3f2fa4de3789787e10ea3ff512863a57 |
|
BLAKE2b-256 | 3440619ceab85694a20d0f83a0b78a9c78bb93f090760f3309f82ed8dad35d2e |