When you mention dynamic, do you mean that the data has a known set of
possible fields, but may only populate a subset of them? Or will it
just have random fields that you may not know about ahead of time? If
you have a way to articulate all of the possible fields that the data
source may use, then I would suggest creating a large model (or set of
models if needed) to encompass all of the possible data fields with
reasonable defaults. You'll also need to building the appropriate
de-serialization code to drop the various bits of data into those
models.

You can probably write some code to grab the fields and create a
skeleton of a model definition (if the definition will remain static
once built), although it may be difficult to determine whether or not
a particular field should be a Char or an Integer field, etc.

If you are using Postgres as your database backend, you also have the
option of storing the JSON directly into an HStore field. See
https://docs.djangoproject.com/en/dev/ref/contrib/postgres/fields/#hstorefield
for more information.

Django doesn't support the idea of dynamic models since models are
tied directly to the database schema, and I doubt you want to modify
your database schema dynamically based on incoming data.

-James

On Thu, Jul 9, 2015 at 1:20 PM, Shekar Tippur <ctip...@gmail.com> wrote:
> Hello,
>
> I have a source of data that can have a dynamic json structure.
> Is there a way to dynamically create models based on this?
>
> - Shekar
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/49075845-52fe-4e9f-8e66-292491baea0a%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2Be%2BciVkJwRhmcjapti718XoHXszmEq-Qch%2B2Q9%2Bi7CiUmBK%2BQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to