Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Contributing] Thoughts on adding a contrib folder for dataclass support? #75

Open
ghost opened this issue Nov 7, 2022 · 6 comments
Open

Comments

@ghost
Copy link

ghost commented Nov 7, 2022

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

@bhch
Copy link
Owner

bhch commented Nov 7, 2022

Could you please describe the use case for DataclassJSONField?

@ghost
Copy link
Author

ghost commented Nov 7, 2022

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.

@ghost
Copy link
Author

ghost commented Nov 7, 2022

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.

@ghost
Copy link
Author

ghost commented Nov 7, 2022

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)

@bhch
Copy link
Owner

bhch commented Nov 7, 2022

That does sound useful. Alright, I'm open to include this in the library. Kindly open a PR. Thank you.

@dongyuzheng
Copy link

I am @ghost

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants