update docs, add params to json too
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
import sys
|
||||
import warnings
|
||||
from typing import (
|
||||
AbstractSet,
|
||||
Any,
|
||||
@ -774,6 +775,50 @@ class NewBaseModel(pydantic.BaseModel, ModelTableProxy, metaclass=ModelMetaclass
|
||||
|
||||
return dict_instance
|
||||
|
||||
def json( # type: ignore # noqa A003
|
||||
self,
|
||||
*,
|
||||
include: Union[Set, Dict] = None,
|
||||
exclude: Union[Set, Dict] = None,
|
||||
by_alias: bool = False,
|
||||
skip_defaults: bool = None,
|
||||
exclude_unset: bool = False,
|
||||
exclude_defaults: bool = False,
|
||||
exclude_none: bool = False,
|
||||
encoder: Optional[Callable[[Any], Any]] = None,
|
||||
exclude_primary_keys: bool = False,
|
||||
exclude_through_models: bool = False,
|
||||
**dumps_kwargs: Any,
|
||||
) -> str:
|
||||
"""
|
||||
Generate a JSON representation of the model, `include` and `exclude`
|
||||
arguments as per `dict()`.
|
||||
|
||||
`encoder` is an optional function to supply as `default` to json.dumps(),
|
||||
other arguments as per `json.dumps()`.
|
||||
"""
|
||||
if skip_defaults is not None: # pragma: no cover
|
||||
warnings.warn(
|
||||
f'{self.__class__.__name__}.json(): "skip_defaults" is deprecated '
|
||||
f'and replaced by "exclude_unset"',
|
||||
DeprecationWarning,
|
||||
)
|
||||
exclude_unset = skip_defaults
|
||||
encoder = cast(Callable[[Any], Any], encoder or self.__json_encoder__)
|
||||
data = self.dict(
|
||||
include=include,
|
||||
exclude=exclude,
|
||||
by_alias=by_alias,
|
||||
exclude_unset=exclude_unset,
|
||||
exclude_defaults=exclude_defaults,
|
||||
exclude_none=exclude_none,
|
||||
exclude_primary_keys=exclude_primary_keys,
|
||||
exclude_through_models=exclude_through_models,
|
||||
)
|
||||
if self.__custom_root_type__: # pragma: no cover
|
||||
data = data["__root__"]
|
||||
return self.__config__.json_dumps(data, default=encoder, **dumps_kwargs)
|
||||
|
||||
def update_from_dict(self, value_dict: Dict) -> "NewBaseModel":
|
||||
"""
|
||||
Updates self with values of fields passed in the dictionary.
|
||||
|
||||
@ -282,6 +282,9 @@ class QuerysetProxy(Generic[T]):
|
||||
|
||||
Actual call delegated to QuerySet.
|
||||
|
||||
Passing args and/or kwargs is a shortcut and equals to calling
|
||||
`filter(*args, **kwargs).first()`.
|
||||
|
||||
List of related models is cleared before the call.
|
||||
|
||||
:param kwargs:
|
||||
@ -300,7 +303,8 @@ class QuerysetProxy(Generic[T]):
|
||||
|
||||
If no criteria set it will return the last row in db sorted by pk.
|
||||
|
||||
Passing a criteria is actually calling filter(**kwargs) method described below.
|
||||
Passing args and/or kwargs is a shortcut and equals to calling
|
||||
`filter(*args, **kwargs).get_or_none()`.
|
||||
|
||||
If not match is found None will be returned.
|
||||
|
||||
@ -324,7 +328,8 @@ class QuerysetProxy(Generic[T]):
|
||||
|
||||
If no criteria set it will return the last row in db sorted by pk.
|
||||
|
||||
Passing a criteria is actually calling filter(**kwargs) method described below.
|
||||
Passing args and/or kwargs is a shortcut and equals to calling
|
||||
`filter(*args, **kwargs).get()`.
|
||||
|
||||
Actual call delegated to QuerySet.
|
||||
|
||||
@ -346,7 +351,8 @@ class QuerysetProxy(Generic[T]):
|
||||
"""
|
||||
Returns all rows from a database for given model for set filter options.
|
||||
|
||||
Passing kwargs is a shortcut and equals to calling `filter(**kwrags).all()`.
|
||||
Passing args and/or kwargs is a shortcut and equals to calling
|
||||
`filter(*args, **kwargs).all()`.
|
||||
|
||||
If there are no rows meeting the criteria an empty list is returned.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user