use existing encode_json to avoid code duplication, rename queryset customization param and move it to Meta, move docs to models from inheritance
This commit is contained in:
@ -12,18 +12,13 @@ from typing import (
|
||||
cast,
|
||||
)
|
||||
|
||||
try:
|
||||
import orjson as json
|
||||
except ImportError: # pragma: no cover
|
||||
import json # type: ignore
|
||||
|
||||
import pydantic
|
||||
|
||||
import ormar # noqa: I100, I202
|
||||
from ormar.exceptions import ModelPersistenceError
|
||||
from ormar.fields.parsers import encode_json
|
||||
from ormar.models.mixins import AliasMixin
|
||||
from ormar.models.mixins.relation_mixin import RelationMixin
|
||||
from ormar.queryset.utils import to_str
|
||||
|
||||
if TYPE_CHECKING: # pragma: no cover
|
||||
from ormar import ForeignKeyField, Model
|
||||
@ -208,8 +203,8 @@ class SavePrepareMixin(RelationMixin, AliasMixin):
|
||||
:rtype: Dict
|
||||
"""
|
||||
for key, value in model_dict.items():
|
||||
if key in cls._json_fields and not isinstance(value, str):
|
||||
model_dict[key] = to_str(json.dumps(value))
|
||||
if key in cls._json_fields:
|
||||
model_dict[key] = encode_json(value)
|
||||
return model_dict
|
||||
|
||||
@classmethod
|
||||
|
||||
Reference in New Issue
Block a user