Hallöchen!

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.bron...@jabber.rwth-aachen.de
                                  or http://bronger-jmp.appspot.com

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-developers@googlegroups.com.
To unsubscribe from this group, send email to 
django-developers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en.

Reply via email to