QSet
QSet
¶
QSet(model_class: Type[BaseSBModel], objects: List[BaseSBModel] | None = None)
Lazy database lookup for a set of objects.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_class |
Type[BaseSBModel]
|
The model class. |
required |
objects |
List[BaseSBModel] | None
|
The objects to initialize the QSet with. |
None
|
client
property
¶
client: BaseClient
all
¶
all() -> Self
Get all objects from the database.
Returns:
Type | Description |
---|---|
Self
|
The QSet with all objects. |
Examples:
>>> qs = Model.objects.all()
count
¶
count() -> int
Get the number of objects in the QSet.
Returns:
Type | Description |
---|---|
int
|
The number of objects in the QSet. |
Examples:
>>> count = Model.objects.count()
delete
¶
delete() -> int
Delete the objects in the QSet.
Returns:
Type | Description |
---|---|
int
|
The number of objects deleted. |
Examples:
>>> Model.objects.filter(name='name').delete()
exclude
¶
exclude(**filters) -> Self
Exclude objects from the database with the filters.
Returns:
Type | Description |
---|---|
Self
|
The QSet with the excluded objects. |
Examples:
>>> qs = Model.objects.exclude(name='name')
filter
¶
filter(**filters) -> Self
Filter objects from the database with the filters.
Returns:
Type | Description |
---|---|
Self
|
The QSet with the filtered objects. |
Examples:
>>> qs = Model.objects.filter(name='name')
first
¶
first() -> BaseSBModel | None
Get the first object in the QSet. If the QSet is empty, return None.
Returns:
Type | Description |
---|---|
BaseSBModel | None
|
The first object in the QSet. |
Examples:
>>> first_obj = Model.objects.all().first()
get
¶
get(**filters) -> BaseSBModel | NoReturn
Get an object from the database with the filters. If the object does not exist, raise a DoesNotExist exception. If more than one object exists, raise a MultipleObjectsReturned exception.
Returns:
Type | Description |
---|---|
BaseSBModel
|
The object. |
Raises:
Type | Description |
---|---|
DoesNotExist
|
If the object does not exist or more than one object exists. |
Examples:
>>> obj = Model.objects.get(name='name')
last
¶
last() -> BaseSBModel | None
Get the last object in the QSet. If the QSet is empty, return None.
Returns:
Type | Description |
---|---|
BaseSBModel | None
|
The last object in the QSet. |
Examples:
>>> last_obj = Model.objects.all().last()
update
¶
update(**data) -> int | NoReturn
Update the objects in the QSet with the data. If data is not valid, raise an InvalidField exception.
Returns:
Type | Description |
---|---|
int
|
The number of objects updated. |
Raises:
Type | Description |
---|---|
InvalidField
|
If the field is not valid. |
Examples:
>>> qs = Model.objects.update(name='new_name')