[Contributing] Thoughts on adding a `contrib` folder for `dataclass` support?
Hi @bhch , I'm working on a project which requires django-jsonform + dataclasses-jsonschema.
I feel this project could be quite useful to the Django community. So I want to make this functionality public.
Would you be OK if I make PRs to add a contrib/dataclasses folder?
E.g., from django_jsonform.contrib.dataclasses import DataclassJSONField
Could you please describe the use case for DataclassJSONField?
In the Python code, we'd work with dataclasse, rather than Dicts.
In the DB, it gets stored as a JSON.
Basically dataclass with a JSON schema get serialized/deserialized as JSON.
This makes good sense for django-jsonform because when you require a json schema, then you expect structure. Then the Dataclass would provide structure and utility for the Python side.
Pseudo code example:
@dataclass
class Foo:
x: int
class MyModel:
foo = DataclassJSONField(Foo)
foo_list = DataclassJSONField(Foo, many=True)
m = MyModel.objects.first()
assert isinstance(m.foo, Foo)
assert isinstance(m.foo_list, list)
assert isinstance(m.foo_list[0], Foo)
That does sound useful. Alright, I'm open to include this in the library. Kindly open a PR. Thank you.
I am @ghost