jazzband / jsonmodels

jsonmodels is library to make it easier for you to deal with structures that are converted to, or read from JSON.
http://jsonmodels.readthedocs.org/en/latest/
BSD 3-Clause "New" or "Revised" License
334 stars 51 forks source link

Q: Persisting models to Django ORM? #146

Open Natureshadow opened 3 years ago

Natureshadow commented 3 years ago

I am developing a library that handles data that is exchanged in JSON format. It shall be designed to be easily usable with Django, but not require it.

jsonmodels seems like a good fit to start the modelling process. Has anyone thought about how to link it to Django ORM, as in, optionally persist data in real Django models?

beregond commented 3 years ago

Hey @Natureshadow

If you are creating lib, of which jsonmodels would be a transport layer with optional Django support - then I suggest to put code (in the beginning at least) responsible for that in that very library (as jsonmodels does not have any integration with any framework for now).

As the lib grows - you could make this generic - and extract this as a plugin to your library (or jsonmodels?)

And diving into more details about

Has anyone thought about how to link it to Django ORM, as in, optionally persist data in real Django models?

I'd keep jsonmodels and Django agnostic - and build around them layer that translates/autogenerates models (field by field) - although this is complicated as you can have few approaches like keeping only one-level models (so they are easily translated) or cast deeper json structures as json field or as related model... Plus there is problem how to handle django migrations (especially that Django has to be optional).

So yeah, problem is complicated - you should start with as many constraints and assumptions as possible to make this easier :)