I was recently working with django.core.serializers.python module. It implements both serializer and deserializer classes that enable export/import the Django ORM objects into/from "Python objects". Such an object is actually as dict with a hard-coded set of keys: model (lower-case model label, str), pk (the actual object's database PK value) and fields (a dict with fields names mapped onto their serialized values). Currently, the objects are annotated by dict[str, Any].
If one considered adding some wrappers around the mentioned classes (those in django.core.serializers.json are examples) from django.core.serializers.python, it would be nice to have those "objects" fully annotated, e.g. using TypedDict, something like:
from typing import Any, NotRequired, TypedDict
class PythonSerializedObject(TypedDict):
model: str
pk: NotRequired[Any] # python >= (3, 11)
fields: dict[str, Any]
I hope you will find this idea interesting.
Anyway, I thank all the developers and maintainers of the projects. This is truly a great job done! ❤️
I was recently working with
django.core.serializers.python
module. It implements both serializer and deserializer classes that enable export/import the Django ORM objects into/from "Python objects". Such an object is actually asdict
with a hard-coded set of keys:model
(lower-case model label,str
),pk
(the actual object's database PK value) andfields
(adict
with fields names mapped onto their serialized values). Currently, the objects are annotated bydict[str, Any]
.If one considered adding some wrappers around the mentioned classes (those in
django.core.serializers.json
are examples) fromdjango.core.serializers.python
, it would be nice to have those "objects" fully annotated, e.g. usingTypedDict
, something like:I hope you will find this idea interesting.
Anyway, I thank all the developers and maintainers of the projects. This is truly a great job done! ❤️