Skip to main content

Chain together multiple (disparate) QuerySets to treat them as a single QuerySet.

Project description

https://img.shields.io/pypi/v/django-querysetsequence.svg https://github.com/clokep/django-querysetsequence/actions/workflows/main.yml/badge.svg Documentation Status

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 3.2/4.0/4.1/4.2, 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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-querysetsequence-0.17.tar.gz (30.4 kB view details)

Uploaded Source

Built Distribution

django_querysetsequence-0.17-py3-none-any.whl (16.3 kB view details)

Uploaded Python 3

File details

Details for the file django-querysetsequence-0.17.tar.gz.

File metadata

  • Download URL: django-querysetsequence-0.17.tar.gz
  • Upload date:
  • Size: 30.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for django-querysetsequence-0.17.tar.gz
Algorithm Hash digest
SHA256 056e62d138191c65a3d36ad773ae4ba3adbfd6a776339b62572e7f7cc70d867d
MD5 220163adde3c47d6e7fd37b5af3ec6b1
BLAKE2b-256 998be73e4c4745caf20779f32b0841208ad3d5011a5b5464247f5b4d87ff4dba

See more details on using hashes here.

File details

Details for the file django_querysetsequence-0.17-py3-none-any.whl.

File metadata

  • Download URL: django_querysetsequence-0.17-py3-none-any.whl
  • Upload date:
  • Size: 16.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for django_querysetsequence-0.17-py3-none-any.whl
Algorithm Hash digest
SHA256 02f7c2025dc6fbaf659a91d84eaa333846be1e3530828b283e3f8b7912f49b75
MD5 a106f7c2f11a96940fbcd3ae4065b51a
BLAKE2b-256 f9f87b5a4bf21dbe4ecc5b3d31626318456d3b7c442a74175e7e489d27ba270a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page