Shortcuts
django_spire.core.shortcuts
T = TypeVar('T', bound=Model)
module-attribute
get_object_or_null_obj
Retrieves an object from the given QuerySet or model using the provided keyword arguments.
If the object does not exist, returns a new instance of the model.
Parameters:
-
queryset_or_model
(QuerySet[T] | type[T]
) –A QuerySet or model class to query from.
-
kwargs
–Keyword arguments for filtering the object.
Returns:
-
T
–An instance of the model, either retrieved or a new instance if not found.
Source code in django_spire/core/shortcuts.py
get_object_or_none
Retrieves an object from the given model using its primary key and additional filters.
Parameters:
-
model
(type[T]
) –The model class to query.
-
pk
(int
) –The primary key of the object.
-
kwargs
–Additional filter parameters.
Returns:
-
Model
–The model instance if found, otherwise None.
Source code in django_spire/core/shortcuts.py
process_request_body
Processes the HTTP request body and returns the 'data' field from the parsed JSON.
Parameters:
-
request
(HttpRequest
) –The HTTP request object.
Returns:
-
Any
–The 'data' field extracted from the JSON body.
Source code in django_spire/core/shortcuts.py
model_object_from_app_label
Retrieves a model instance based on the application label, model name, and primary key.
Parameters:
-
app_label
(str
) –The application label of the model.
-
model_name
(str
) –The name of the model.
-
object_pk
(int
) –The primary key of the object.
Returns:
-
Model | None
–The model instance if found, otherwise None.