See #12990 -- this is a ticket that has requested exactly this feature.
You'll also see that with one exception, the core team have all been
-1 or -0 on this idea.
Yours,
Russ Magee %-)
The problem with something like this is that it is rarely a good idea
to stick opaque data into the database that cannot then be queried
upon. You may have a very good reason for doing this, but most of the
time that it happens it ends up being a bad design choice.
Adding this to core would suggest that bad design choices are a-ok in
Django, which is why I expect many people are -0/-1 on this. If I had
a vote, I'd be -1.
Cheers
Tom
This is not in dispute. What is in dispute is that when you have
non-relational data, you should be using a non-relational data store,
not trying to stuff non-relational data into your relational store.
Tom correctly summarized the argument against putting JSONField in
trunk -- it's the wrong tool for the job. If you have non-relational
data, you should be using a non-relational store. Alternatively, you
should be exploiting the non-relational data structures inside a
relational store (e.g., PostgreSQL's hstore).
At a project level, Django has a responsibility to advocate for best
practices. Using the wrong tool for the job isn't best practice. If
you really do need a JSONField, Django gives you the abilty to add one
yourself as an external dependency, and for my money, that's the right
place for JSONField to live.
Yours,
Russ Magee %-)
Tom Evans writes:
> On Sat, Nov 5, 2011 at 11:48 AM, Ric wrote:
>
>> this is my proposition to have custom data inside a model field
>>
>> a json data field, the code is simple as this, and it works with
>> lastest django release
>
> The problem with something like this is that it is rarely a good
> idea to stick opaque data into the database that cannot then be
> queried upon. [...]
>
> Adding this to core would suggest that bad design choices are a-ok
> in Django, which is why I expect many people are -0/-1 on this.
While I appreciate that Django core is supposed to enforce good
design practices, one must be careful with that if some practice may
have valid use cases. You cannot prevent the user from shooting in
the foot anyway.
While we make extensive use of the relational model in our project,
I remembered to have a couple of JSON fields (though we don't have a
field class them them so far), so I skimmed through our code to see
why we did this.
In our code, a JSON field is an application of the KISS principle.
I see at least two valid use cases for such fields:
1. You say that you will never query for the content of a field.
For example, we store user preferences in a JSON field. I'll
never be interested in all users who set their page skin to
"classic". (And if I would, I could still do a "manual" query or
do the schema and data migration. This is okay as long as its
probability is sufficiently small.)
Moreover, in some cases, realising the JSON field explicitly in
the relational model would have led to many tiny models. This
may also be bad for performance, but it is certainly bad for
readability and maintenance.
2. Dynamic typing. In one case, we simply don't know a priori how
the data structure in the JSON field will look like. The Python
code interprets its content depending on another field value of
the model instance. The alternative would have been extensive
use of multi-table inheritance.
Tsch�,
Torsten.
--
Torsten Bronger Jabber ID: torsten...@jabber.rwth-aachen.de
or http://bronger-jmp.appspot.com
Hi, I'm sorry you felt that I was being arrogant - I don't know the
situations of your project, it may well be exactly what is needed in
that situation.
I was only trying to point out why in general it is not a good idea to
do this, and why that would mean it shouldn't be in core.
Cheers
Tom
And so do I - the main point here is that we have both successfully
loaded the gun and aimed it at our foot without this field existing in
core. I think it's important to have that distinction between things
you can do and things you should do, in order to make you think
"should I really be doing this".
Cheers
Tom