Skip to main content

dj-queryset-manager

A Django utility that makes it simple to write DRY queryset methods.

Warning

dj-queryset-manager only works with Django versions 1.2 through 1.6.

In Django 1.7 it has been superseded by QuerySet.as_manager(). See the docs.

Usage

  1. Create a manager class that inherit the QuerySetManager

  2. Decorate your filter methods with queryset_method. These methods receive a queryset instead of a manager as the first argument.

from dj_queryset_manager import QuerySetManager, queryset_method

class MyManager(QuerySetManager):
    @queryset_method
    def by_slug(queryset, slug):
        return queryset.filter(slug=slug)

    @queryset_method
    def filter(queryset, *args, **kwargs):
        return super(type(queryset), queryset).filter(*args, **kwargs)

For reference, here is a standard implementation:

from django.db.models import Manager
from django.db.models.query import QuerySet

class MyQuerySet(QuerySet):
    def by_slug(self, slug):
        return self.filter(slug=slug)

    def filter(self, *args, **kwargs):
        return super(MyQuerySet, self).filter(*args, **kwargs)


class MyManager(Manager):
    def get_query_set(self): # Better remember the arguments to QuerySet
        QuerySet(self.model, using=self._db)

    def get_queryset(self): # And don't forget about Django 1.6
        return self.get_query_set()

    def by_slug(self, *args, **kwargs):  # Enjoy this duplicate signature
        return self.get_queryset().filter(*args, **kwargs)

Mix-in

Some third-party apps ship managers as part of their API. If you need to extend any existing manager, use the QuerySetManagerMixin. This example uses the InheritanceManager from django-model-utils.

from model_utils.managers import InheritanceManager
from dj_queryset_manager import QuerySetManagerMixin, queryset_method

class MyInheritanceManager(QuerySetManagerMixin, InheritanceManager):
    @queryset_method
    def by_slug(queryset, slug):
        return queryset.filter(slug=slug)

Installation

$ pip install dj-queryset-manager

Metadata

Release files for dj-queryset-manager 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dj-queryset-manager 0.1.3
File Size Uploaded Provenance Actions
dj-queryset-manager-0.1.3.tar.gz 3.6 kB Without provenance Details for dj-queryset-manager-0.1.3.tar.gz

Release files / dj-queryset-manager-0.1.3.tar.gz

Download URL dj-queryset-manager-0.1.3.tar.gz
Size 3.6 kB
Tags Source
SHA-256 checksum
How to use checksums
0effdba31d6d9abddd8fd1386337ad5de1403c3156607dae2188c7bcbc75a410
BLAKE2b-256 checksum
How to use checksums
feaaa51fffa00e1039fb08ea1e552fd96b0c159117254cb528187aa54847a84e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for dj-queryset-manager 0.1.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page