Skip to content

QuerySet

QuerySet provides functionality to make queries to configured databases.

amsdal_models.querysets.base_queryset.QuerySetBase

Bases: typing.Generic

Base class for QuerySets.

This class provides the base functionality for creating and manipulating query sets for model instances. It includes methods for filtering, ordering, and executing queries, as well as handling pagination and distinct results.

distinct method descriptor

distinct(fields)

Return only distinct (different) values.

This method creates a copy of the current query set and sets the distinct attribute to the specified fields, ensuring that only distinct values are returned in the query results.

Args: fields (list[str]): The fields to be distinct.

Returns: Self: A new instance of the query set with the specified distinct fields.

entity property

entity

Get the entity associated with the query set.

This property returns the model class associated with the query set.

Returns: type[ModelType]: The model class.

entity_name property

entity_name

Get the name of the entity associated with the query set.

This property returns the name of the model class associated with the query set.

Returns: str: The name of the model class.

exclude method descriptor

exclude(*args, **kwargs)

Exclude filters from the query. The filters are combined with AND.

Args: args (Q): The filters to be applied. kwargs (Any): The filters to be applied.

Returns: Self: A new instance of the query set with the applied filters.

filter method descriptor

filter(*args, **kwargs)

Apply filters to the query. The filters are combined with AND.

Args: args (Q): The filters to be applied. kwargs (Any): The filters to be applied.

Returns: Self: A new instance of the query set with the applied filters.

get_conditions method descriptor

get_conditions()

Get the conditions of the query set.

This property returns the conditions of the query set.

Returns: Q | None: The conditions of the query set.

get_order_by method descriptor

get_order_by()

Get the order by fields of the query set.

This property returns the order by fields of the query set.

Returns: list[OrderBy]: The order by fields of the query set.

get_paginator method descriptor

get_paginator()

Get the paginator of the query set.

This property returns the paginator of the query set.

Returns: NumberPaginator: The paginator of the query set.

get_query_specifier method descriptor

get_query_specifier()

Get the query specifier of the query set.

This property returns the query specifier of the query set.

Returns: QuerySpecifier: The query specifier of the query set.

get_select_related()

Get the related objects to include in the query results.

This property returns the related objects to include in the query results.

Returns: bool | dict[str, Any]: The related objects to include in the query results.

get_using method descriptor

get_using()

Get the database alias used for the query.

This property returns the database alias used for the query.

Returns: str: The database alias used for the query.

latest method descriptor

latest()

Filter the query set to include only the latest version of the model instances.

This method creates a copy of the current query set and applies a filter to include only the latest version of the model instances.

Returns: Self: A new instance of the query set with the filter applied to include only the latest version of the model instances.

only method descriptor

only(fields)

Limit the number of fields to be returned.

This method creates a copy of the current query set and sets the only attribute to the specified fields, limiting the fields to be returned in the query results.

Args: fields (list[str]): The fields to be returned.

Returns: Self: A new instance of the query set with the specified fields.

order_by method descriptor

order_by(*args)

Order the query by the given fields.

Args: args (str): The fields to order by.

Returns: Self: A new instance of the query set with the specified order.

select_related(*fields)

Include related objects in the query results.

Args: *fields (str): The related objects to include in the query results.

Returns: Self: A new instance of the query set with the specified related objects.

using method descriptor

using(value)

Set the database alias to be used for the query.

This method creates a copy of the current query set and sets the _using attribute to the specified database alias.

Args: value (str): The database alias to be used for the query.

Returns: Self: A new instance of the query set with the specified database alias.

amsdal_models.querysets.base_queryset.QuerySet

Bases: amsdal_models.querysets.base_queryset.QuerySetBase, typing.Generic

Interface to access the database.

This class provides methods to create and manipulate query sets for model instances. It includes methods for filtering, ordering, and executing queries, as well as handling pagination and distinct results.

count method descriptor

count()

Change the QuerySet to a QuerySetCount. Query execution will return the count of items.

Returns: QuerySetCount: A new instance of the QuerySetCount.

distinct method descriptor

distinct(fields)

Return only distinct (different) values.

This method creates a copy of the current query set and sets the distinct attribute to the specified fields, ensuring that only distinct values are returned in the query results.

Args: fields (list[str]): The fields to be distinct.

Returns: Self: A new instance of the query set with the specified distinct fields.

exclude method descriptor

exclude(*args, **kwargs)

Exclude filters from the query. The filters are combined with AND.

This method creates a copy of the current query set and applies the specified filters to exclude certain results. The filters can be provided as positional arguments or keyword arguments, and they are combined using the AND operator.

Args: args (Q): The filters to be applied as positional arguments. *kwargs (Any): The filters to be applied as keyword arguments.

Returns: Self: A new instance of the query set with the applied exclusion filters.

execute method descriptor

execute()

Return the list of items.

This method executes the query and returns a list of model instances. If the only attribute is set, partial model instances are created.

Returns: list[ModelType]: A list of model instances.

filter method descriptor

filter(*args, **kwargs)

Apply filters to the query. The filters are combined with AND.

This method creates a copy of the current query set and applies the specified filters to it. The filters can be provided as positional arguments or keyword arguments, and they are combined using the AND operator.

Args: args (Q): The filters to be applied as positional arguments. *kwargs (Any): The filters to be applied as keyword arguments.

Returns: Self: A new instance of the query set with the applied filters.

first method descriptor

first(*args, **kwargs)

Change the QuerySet to a QuerySetOne. Query execution will return the first item or None.

Args: args (Q): The filters to be applied. kwargs (Any): The filters to be applied.

Returns: QuerySetOneRequired: A new instance of the QuerySetOneRequired with the applied filters.

get method descriptor

get(*args, **kwargs)

Change the QuerySet to a QuerySetOneRequired. Query execution will return a single item or raise an error.

Args: args (Q): The filters to be applied. kwargs (Any): The filters to be applied.

Returns: QuerySetOneRequired: A new instance of the QuerySetOneRequired with the applied filters.

get_or_none method descriptor

get_or_none(*args, **kwargs)

Change the QuerySet to a QuerySetOne. Query execution will return a single item or None.

Args: args (Q): The filters to be applied. kwargs (Any): The filters to be applied.

Returns: QuerySetOne: A new instance of the QuerySetOne with the applied filters.

only method descriptor

only(fields)

Limit the number of fields to be returned.

This method creates a copy of the current query set and sets the only attribute to the specified fields, limiting the fields to be returned in the query results.

Args: fields (list[str]): The fields to be returned.

Returns: Self: A new instance of the query set with the specified fields.

order_by method descriptor

order_by(*args)

Order the query by the given fields.

This method creates a copy of the current query set and sets the order_by attribute to the specified fields, determining the order of the query results.

Args: *args (str): The fields to order by.

Returns: Self: A new instance of the query set with the specified order.

select_related(*fields)

Include related objects in the query results.

This method creates a copy of the current query set and sets the select_related attribute to the specified fields, including related objects in the query results.

Args: *fields (str): The related objects to include in the query results.

Returns: Self: A new instance of the query set with the specified related objects.

amsdal_models.querysets.base_queryset.QuerySetOne

Bases: amsdal_models.querysets.base_queryset.QuerySetBase, typing.Generic

QuerySet class for models. QuerySet is executed to a single model object or None.

This class provides methods to create and manipulate query sets for model instances. It includes methods for filtering, ordering, and executing queries, as well as handling pagination and distinct results. The query execution will return a single item or None.

distinct method descriptor

distinct(fields)

Return only distinct (different) values.

This method creates a copy of the current query set and sets the distinct attribute to the specified fields, ensuring that only distinct values are returned in the query results.

Args: fields (list[str]): The fields to be distinct.

Returns: Self: A new instance of the query set with the specified distinct fields.

exclude method descriptor

exclude(*args, **kwargs)

Exclude filters from the query. The filters are combined with AND.

This method creates a copy of the current query set and applies the specified filters to exclude certain results. The filters can be provided as positional arguments or keyword arguments, and they are combined using the AND operator.

Args: args (Q): The filters to be applied as positional arguments. *kwargs (Any): The filters to be applied as keyword arguments.

Returns: Self: A new instance of the query set with the applied exclusion filters.

execute method descriptor

execute()

Query the database and return the single item or None.

This method executes the query and returns a single model instance or None. If multiple items are found, a MultipleObjectsReturnedError is raised.

Raises: MultipleObjectsReturnedError: If multiple items are found.

Returns: ModelType | None: The single model instance or None if no items are found.

filter method descriptor

filter(*args, **kwargs)

Apply filters to the query. The filters are combined with AND.

This method creates a copy of the current query set and applies the specified filters to it. The filters can be provided as positional arguments or keyword arguments, and they are combined using the AND operator.

Args: args (Q): The filters to be applied as positional arguments. *kwargs (Any): The filters to be applied as keyword arguments.

Returns: Self: A new instance of the query set with the applied filters.

only method descriptor

only(fields)

Limit the number of fields to be returned.

This method creates a copy of the current query set and sets the only attribute to the specified fields, limiting the fields to be returned in the query results.

Args: fields (list[str]): The fields to be returned.

Returns: Self: A new instance of the query set with the specified fields.

order_by method descriptor

order_by(*args)

Order the query by the given fields.

This method creates a copy of the current query set and sets the order_by attribute to the specified fields, determining the order of the query results.

Args: *args (str): The fields to order by.

Returns: Self: A new instance of the query set with the specified order.

amsdal_models.querysets.base_queryset.QuerySetOneRequired

Bases: amsdal_models.querysets.base_queryset.QuerySetOne, typing.Generic

QuerySet class for models. QuerySet is executed to a single model object or raises an error.

This class provides methods to create and manipulate query sets for model instances. It includes methods for filtering, ordering, and executing queries, as well as handling pagination and distinct results. The query execution will return a single item or raise an error if no items are found.

distinct method descriptor

distinct(fields)

Return only distinct (different) values.

This method creates a copy of the current query set and sets the distinct attribute to the specified fields, ensuring that only distinct values are returned in the query results.

Args: fields (list[str]): The fields to be distinct.

Returns: Self: A new instance of the query set with the specified distinct fields.

exclude method descriptor

exclude(*args, **kwargs)

Exclude filters from the query. The filters are combined with AND.

This method creates a copy of the current query set and applies the specified filters to exclude certain results. The filters can be provided as positional arguments or keyword arguments, and they are combined using the AND operator.

Args: args (Q): The filters to be applied as positional arguments. *kwargs (Any): The filters to be applied as keyword arguments.

Returns: Self: A new instance of the query set with the applied exclusion filters.

execute method descriptor

execute()

Return the single item.

This method executes the query and returns a single model instance. If no items are found, an ObjectDoesNotExistError is raised.

Raises: ObjectDoesNotExistError: If no items are found.

Returns: ModelType: The single model instance.

filter method descriptor

filter(*args, **kwargs)

Apply filters to the query. The filters are combined with AND.

This method creates a copy of the current query set and applies the specified filters to it. The filters can be provided as positional arguments or keyword arguments, and they are combined using the AND operator.

Args: args (Q): The filters to be applied as positional arguments. *kwargs (Any): The filters to be applied as keyword arguments.

Returns: Self: A new instance of the query set with the applied filters.

only method descriptor

only(fields)

Limit the number of fields to be returned.

This method creates a copy of the current query set and sets the only attribute to the specified fields, limiting the fields to be returned in the query results.

Args: fields (list[str]): The fields to be returned.

Returns: Self: A new instance of the query set with the specified fields.

order_by method descriptor

order_by(*args)

Order the query by the given fields.

This method creates a copy of the current query set and sets the order_by attribute to the specified fields, determining the order of the query results.

Args: *args (str): The fields to order by.

Returns: Self: A new instance of the query set with the specified order.

amsdal_models.querysets.base_queryset.QuerySetCount

Bases: amsdal_models.querysets.base_queryset.QuerySetBase, typing.Generic

QuerySet class for models. QuerySet is executed to a count of items.

This class provides methods to create and manipulate query sets for model instances. It includes methods for filtering, ordering, and executing queries, as well as handling pagination and distinct results. The query execution will return the count of items.

distinct method descriptor

distinct(fields)

Return only distinct (different) values.

This method creates a copy of the current query set and sets the distinct attribute to the specified fields, ensuring that only distinct values are returned in the query results.

Args: fields (list[str]): The fields to be distinct.

Returns: Self: A new instance of the query set with the specified distinct fields.

exclude method descriptor

exclude(*args, **kwargs)

Exclude filters from the query. The filters are combined with AND.

This method creates a copy of the current query set and applies the specified filters to exclude certain results. The filters can be provided as positional arguments or keyword arguments, and they are combined using the AND operator.

Args: args (Q): The filters to be applied as positional arguments. *kwargs (Any): The filters to be applied as keyword arguments.

Returns: Self: A new instance of the query set with the applied exclusion filters.

execute method descriptor

execute()

Return the count of items.

This method executes the query and returns the count of model instances that match the query criteria.

Returns: int: The count of model instances.

filter method descriptor

filter(*args, **kwargs)

Apply filters to the query. The filters are combined with AND.

This method creates a copy of the current query set and applies the specified filters to it. The filters can be provided as positional arguments or keyword arguments, and they are combined using the AND operator.

Args: args (Q): The filters to be applied as positional arguments. *kwargs (Any): The filters to be applied as keyword arguments.

Returns: Self: A new instance of the query set with the applied filters.

only method descriptor

only(fields)

Limit the number of fields to be returned.

This method creates a copy of the current query set and sets the only attribute to the specified fields, limiting the fields to be returned in the query results.

Args: fields (list[str]): The fields to be returned.

Returns: Self: A new instance of the query set with the specified fields.

order_by method descriptor

order_by(*args)

Order the query by the given fields.

This method creates a copy of the current query set and sets the order_by attribute to the specified fields, determining the order of the query results.

Args: *args (str): The fields to order by.

Returns: Self: A new instance of the query set with the specified order.