• Get Review Board
  • What's New
  • Products
  • Review Board Code review, image review, and document review
  • Documentation
  • Release Notes
  • Power Pack Enterprise integrations, reports, and enhanced document review
  • Try for 60 Days
  • Purchase
  • RBCommons Review Board as a Service, hosted by us
  • Pricing
  • RBTools Command line tools and Python API for Review Board
  • Documentation
  • Release Notes
  • Review Bot Automated code review, connecting tools you already use
  • Documentation
  • Release Notes
  • RB Gateway Manage Git and Mercurial repositories in your network
  • Documentation
  • Release Notes
  • Learn and Explore
  • What is Code Review?
  • Documentation
  • Frequently Asked Questions
  • Support Options
  • Third-Party Integrations
  • Demo
  • Review Board RBTools Power Pack Review Bot Djblets RB Gateway
    1. Djblets 3.x
    2. Version 5.x
    3. Version 4.x
    4. Version 3.x
    5. Version 2.x
    6. Version 2.0
    7. Version 1.0
    8. Version 0.9
    9. Djblets Documentation
    10. Module and Class References
    11. djblets.db.query
  • Home
  • Guides
  • Avatar Services Guides
  • Writing Avatar Services
  • Extension Guides
  • Writing Extensions
  • Testing Extensions
  • Feature Checks Guides
  • Introduction to Feature Checks
  • Writing Features
  • Writing Feature Checkers
  • Testing with Feature Checks
  • Integration Guides
  • Supporting Integrations
  • Writing Integrations
  • Privacy Compliance Guides
  • Getting and Checking Consent
  • Working with Personally Identifiable Information
  • Service Integrations
  • reCAPTCHA Guides
  • Using reCAPTCHA
  • Registries Guides
  • Writing Registries
  • Web API Guides
  • Writing Web API Resources
  • Adding OAuth2 Support
  • Module and Class References
  • djblets
  • djblets.deprecation
  • djblets.auth.forms
  • djblets.auth.ratelimit
  • djblets.auth.signals
  • djblets.auth.util
  • djblets.auth.views
  • djblets.avatars.errors
  • djblets.avatars.forms
  • djblets.avatars.registry
  • djblets.avatars.services
  • djblets.avatars.services.base
  • djblets.avatars.services.fallback
  • djblets.avatars.services.file_upload
  • djblets.avatars.services.gravatar
  • djblets.avatars.services.url
  • djblets.avatars.settings
  • djblets.cache.backend
  • djblets.cache.backend_compat
  • djblets.cache.context_processors
  • djblets.cache.errors
  • djblets.cache.forwarding_backend
  • djblets.cache.serials
  • djblets.cache.synchronizer
  • djblets.conditions
  • djblets.conditions.choices
  • djblets.conditions.conditions
  • djblets.conditions.errors
  • djblets.conditions.operators
  • djblets.conditions.values
  • djblets.configforms.forms
  • djblets.configforms.mixins
  • djblets.configforms.pages
  • djblets.configforms.registry
  • djblets.configforms.views
  • djblets.datagrid.grids
  • djblets.db.backends.mysql.base
  • djblets.db.fields
  • djblets.db.fields.base64_field
  • djblets.db.fields.counter_field
  • djblets.db.fields.json_field
  • djblets.db.fields.modification_timestamp_field
  • djblets.db.fields.relation_counter_field
  • djblets.db.managers
  • djblets.db.query
  • djblets.db.validators
  • djblets.extensions.admin
  • djblets.extensions.errors
  • djblets.extensions.extension
  • djblets.extensions.forms
  • djblets.extensions.hooks
  • djblets.extensions.loaders
  • djblets.extensions.manager
  • djblets.extensions.middleware
  • djblets.extensions.models
  • djblets.extensions.packaging
  • djblets.extensions.resources
  • djblets.extensions.settings
  • djblets.extensions.signals
  • djblets.extensions.staticfiles
  • djblets.extensions.testing
  • djblets.extensions.testing.testcases
  • djblets.extensions.urls
  • djblets.extensions.views
  • djblets.extensions.templatetags.djblets_extensions
  • djblets.features
  • djblets.features.checkers
  • djblets.features.decorators
  • djblets.features.errors
  • djblets.features.feature
  • djblets.features.level
  • djblets.features.registry
  • djblets.features.testing
  • djblets.features.templatetags.features
  • djblets.feedview.views
  • djblets.feedview.templatetags.feedtags
  • djblets.forms.fields
  • djblets.forms.fieldsets
  • djblets.forms.forms
  • djblets.forms.forms.key_value_form
  • djblets.forms.widgets
  • djblets.gravatars
  • djblets.gravatars.templatetags.gravatars
  • djblets.http.middleware
  • djblets.integrations.errors
  • djblets.integrations.forms
  • djblets.integrations.hooks
  • djblets.integrations.integration
  • djblets.integrations.manager
  • djblets.integrations.mixins
  • djblets.integrations.models
  • djblets.integrations.urls
  • djblets.integrations.views
  • djblets.log
  • djblets.log.middleware
  • djblets.log.siteconfig
  • djblets.log.urls
  • djblets.log.views
  • djblets.mail.dmarc
  • djblets.mail.message
  • djblets.mail.testing
  • djblets.mail.utils
  • djblets.markdown
  • djblets.markdown.extensions.escape_html
  • djblets.markdown.extensions.wysiwyg
  • djblets.markdown.extensions.wysiwyg_email
  • djblets.pipeline.compilers.es6.ES6Compiler
  • djblets.pipeline.compilers.less.LessCompiler
  • djblets.pipeline.settings
  • djblets.privacy.consent
  • djblets.privacy.consent.base
  • djblets.privacy.consent.common
  • djblets.privacy.consent.errors
  • djblets.privacy.consent.forms
  • djblets.privacy.consent.hooks
  • djblets.privacy.consent.registry
  • djblets.privacy.consent.tracker
  • djblets.privacy.models
  • djblets.privacy.pii
  • djblets.privacy.templatetags.djblets_privacy
  • djblets.recaptcha.mixins
  • djblets.recaptcha.siteconfig
  • djblets.recaptcha.templatetags.djblets_recaptcha
  • djblets.recaptcha.widgets
  • djblets.registries
  • djblets.registries.errors
  • djblets.registries.importer
  • djblets.registries.mixins
  • djblets.registries.registry
  • djblets.registries.signals
  • djblets.secrets
  • djblets.secrets.crypto
  • djblets.secrets.token_generators
  • djblets.secrets.token_generators.base
  • djblets.secrets.token_generators.legacy_sha1
  • djblets.secrets.token_generators.registry
  • djblets.secrets.token_generators.vendor_checksum
  • djblets.siteconfig
  • djblets.siteconfig.admin
  • djblets.siteconfig.context_processors
  • djblets.siteconfig.django_settings
  • djblets.siteconfig.forms
  • djblets.siteconfig.managers
  • djblets.siteconfig.middleware
  • djblets.siteconfig.models
  • djblets.siteconfig.signals
  • djblets.siteconfig.views
  • djblets.template.caches
  • djblets.template.context
  • djblets.template.loaders.conditional_cached
  • djblets.template.loaders.namespaced_app_dirs
  • djblets.testing.decorators
  • djblets.testing.testcases
  • djblets.testing.testrunners
  • djblets.urls.context_processors
  • djblets.urls.decorators
  • djblets.urls.patterns
  • djblets.urls.resolvers
  • djblets.urls.root
  • djblets.urls.staticfiles
  • djblets.util.compat.django.core.cache
  • djblets.util.compat.python.past
  • djblets.util.contextmanagers
  • djblets.util.dates
  • djblets.util.decorators
  • djblets.util.filesystem
  • djblets.util.html
  • djblets.util.http
  • djblets.util.humanize
  • djblets.util.json_utils
  • djblets.util.properties
  • djblets.util.serializers
  • djblets.util.symbols
  • djblets.util.templatetags.djblets_deco
  • djblets.util.templatetags.djblets_email
  • djblets.util.templatetags.djblets_forms
  • djblets.util.templatetags.djblets_images
  • djblets.util.templatetags.djblets_js
  • djblets.util.templatetags.djblets_utils
  • djblets.util.typing
  • djblets.util.views
  • djblets.views.generic.base
  • djblets.views.generic.etag
  • djblets.webapi.auth
  • djblets.webapi.auth.backends
  • djblets.webapi.auth.backends.api_tokens
  • djblets.webapi.auth.backends.base
  • djblets.webapi.auth.backends.basic
  • djblets.webapi.auth.backends.oauth2_tokens
  • djblets.webapi.auth.views
  • djblets.webapi.decorators
  • djblets.webapi.encoders
  • djblets.webapi.errors
  • djblets.webapi.fields
  • djblets.webapi.managers
  • djblets.webapi.models
  • djblets.webapi.oauth2_scopes
  • djblets.webapi.resources
  • djblets.webapi.resources.base
  • djblets.webapi.resources.group
  • djblets.webapi.resources.registry
  • djblets.webapi.resources.root
  • djblets.webapi.resources.user
  • djblets.webapi.resources.mixins.api_tokens
  • djblets.webapi.resources.mixins.forms
  • djblets.webapi.resources.mixins.oauth2_tokens
  • djblets.webapi.resources.mixins.queries
  • djblets.webapi.responses
  • djblets.webapi.signals
  • djblets.webapi.testing
  • djblets.webapi.testing.decorators
  • djblets.webapi.testing.testcases
  • General Index
  • Python Module Index
  • Release Notes
  • This documentation covers Djblets 3.x. You can select a version above or view the latest documentation.

    djblets.db.query¶

    class LocalDataQuerySet(data)¶

    Bases: object

    A QuerySet that operates on generic data provided by the caller.

    This can be used in some circumstances when code requires a QuerySet, but where the data doesn’t come from the database. The caller can instantiate one of these and provide it.

    This doesn’t perform full support for all of QuerySet’s abilities. It does, however, support the following basic functions:

    • all

    • clone

    • count

    • exclude

    • filter

    • get

    • order_by

    • prefetch_related

    • select_related

    As well as the operators expected by consumers of QuerySet, such as __len__ and __iter__.

    This is particularly handy with WebAPIResource.

    PROPERTY_REGEX = re.compile('(-?)(\\w+)')¶
    __init__(data)¶
    all()¶

    Returns a cloned copy of this queryset.

    clone()¶

    Returns a cloned copy of this queryset.

    count()¶

    Returns the number of items in this queryset.

    exclude(**kwargs)¶

    Returns a queryset excluding items from this queryset.

    The result will be a LocalDataQuerySet that contains all items from this queryset that do not contain attributes with values matching those that were passed to this function as keyword arguments.

    filter(**kwargs)¶

    Returns a queryset filtering items from this queryset.

    The result will be a LocalDataQuerySet that contains all items from this queryset that contain attributes with values matching those that were passed to this function as keyword arguments.

    get(**kwargs)¶

    Returns a single result from this queryset.

    This will return a single result from the list of items in this queryset. If keyword arguments are provided, they will be used to filter the queryset down.

    There must be only one item in the queryset matching the given criteria, or a MultipleObjectsReturned will be raised. If there are no items, then an ObjectDoesNotExist will be raised.

    order_by(*attrs, **kwargs)¶

    Returns a queryset ordering items by the specified attributes.

    The result will be a LocalDataQuerySet that contains all items from this queryset ordered by the attributes specified. If multiple attributes are specified, the items are sorted by the first attribute and ties are broken by the other following attributes.

    All items are sorted in ascending order. To specify a descending order, an attribute must have a ‘-’ prepended to the name, such as -attribute_A.

    prefetch_related(*args, **kwargs)¶

    Stub for compatibility with QuerySet.prefetch_related.

    This will simply return a clone of this queryset.

    select_related(*args, **kwargs)¶

    Stub for compatibility with QuerySet.select_related.

    This will simply return a clone of this queryset.

    __contains__(i)¶
    __getitem__(i)¶
    __getslice__(i, j)¶
    __iter__()¶
    __len__()¶
    get_object_or_none(cls, *args, **kwargs)¶

    Return a model instance or None if one can not be found.

    Parameters:
    • cls (type or django.db.models.manager.Manager) – Either the model, a subclass of django.db.models.Model, or its manager.

    • *args (tuple) – Arguments to pass to get().

    • **kwargs (dict) – Keyword arguments to pass to get().

    Returns:

    The model instance, if it could be found, or None otherwise.

    Return type:

    django.db.models.Model

    prefix_q(prefix, q, clone=True)¶

    Prefix a query expression.

    A query expression is used in Manager.get and Manager.filter methods. These expressions are made of a tree of key-value pairs.

    Prefixing these expressions allows a query expression for one model to be used in a related model. The resulting prefixed expression will have every key in every key-value pair prefixed with the given prefix.

    By default, the query expression will be cloned. That is, the given query expression will not be modified and a prefixed copy will be returned.

    Parameters:
    • prefix (unicode) – The prefix to add to each member in the expression. This should be the name of a field and will be automatically suffixed by __.

    • q (django.db.models.query_utils.Q) – The expression to prefix.

    • clone (bool) – Determine if the query should be cloned. If this is False, q will be modified in place. This defaults to True.

    Returns:

    The prefixed query expression.

    Return type:

    django.db.models.query_utils.Q

    Example usage:
    from django.db import models
    from django.db.query_utils import Q
    from djblets.db.query import prefix_q
    
    # Given the following models:
    class A(models.Model):
        foo = models.IntegerField()
        bar = models.IntegerField()
    
    class B(models.Model):
        fk = models.ForeignKey(A, on_delete=models.CASCADE)
        baz = models.IntegerField()
    
    # And the following query expressions:
    a_q = Q(foo=1) & Q(bar=2)
    b_q = Q(fk__foo=1) & Q(fk__bar=2)
    
    # The following queries are equivalent:
    B.objects.filter(b_q)
    B.objects.filter(prefix_q('fk', a_q))
    

    Keep up with the latest Review Board releases, security updates, and helpful information.

    About
    News
    Demo
    RBCommons Hosting
    Integrations
    Happy Users
    Support Options
    Documentation
    FAQ
    User Manual
    RBTools
    Administration Guide
    Power Pack
    Release Notes
    Downloads
    Review Board
    RBTools
    Djblets
    Power Pack
    Package Store
    PGP Signatures
    Contributing
    Bug Tracker
    Submit Patches
    Development Setup
    Wiki
    Follow Us
    Mailing Lists
    Reddit
    Twitter
    Mastodon
    Facebook
    YouTube

    Copyright © 2006-2025 Beanbag, Inc. All rights reserved.

    Terms of Service — Privacy Policy — AI Ethics Policy — Branding

    On this page

    • [Top]
    • LocalDataQuerySet
      • LocalDataQuerySet.PROPERTY_REGEX
      • LocalDataQuerySet.__init__()
      • LocalDataQuerySet.all()
      • LocalDataQuerySet.clone()
      • LocalDataQuerySet.count()
      • LocalDataQuerySet.exclude()
      • LocalDataQuerySet.filter()
      • LocalDataQuerySet.get()
      • LocalDataQuerySet.order_by()
      • LocalDataQuerySet.prefetch_related()
      • LocalDataQuerySet.select_related()
      • LocalDataQuerySet.__contains__()
      • LocalDataQuerySet.__getitem__()
      • LocalDataQuerySet.__getslice__()
      • LocalDataQuerySet.__iter__()
      • LocalDataQuerySet.__len__()
    • get_object_or_none()
    • prefix_q()