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

Setting JSONField schema dynamically #145

Closed
ErikKoinberg opened this issue Feb 7, 2024 · 3 comments
Closed

Setting JSONField schema dynamically #145

ErikKoinberg opened this issue Feb 7, 2024 · 3 comments

Comments

@ErikKoinberg
Copy link

I have a situation where a user needs to define a template structure for something. Based on the data in this first JSONField, I am able to create a new schema dynamically, derived from the user input into the first model.

The thing now is that I want to set this derived schema to be the Schema for a JSONField of the instance of another Model (which has a foreignkey to the first model). Is this possible in any way? I found it hard to implement since:

field =JSONField(schema = my_schema)

Is declared class-wise for the model. Is there any way to change the schema of the JSONField of an instance of a model containing a django-jsonform JSONField? Otherwise, is there a workaround for this?

@ErikKoinberg
Copy link
Author

I was able to solve this by reading about callable schemas as described in a previous issue. I did however use the hacky version and could not find a cleaner implementation in the docs.

@bhch
Copy link
Owner

bhch commented Feb 8, 2024

I did however use the hacky version and could not find a cleaner implementation in the docs.

Could you give me an example of what a cleaner implementation would look like?

I've though of a couple of solutions but it's kind of tricky to add them without breaking changes.

@ErikKoinberg
Copy link
Author

I understand. Actually, it was fine and not that hard to do. And it works.

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