On Feb 13, 10:31 pm, "django_fo...@codechimp.net"
<codech...@gmail.com> wrote:
> By multiple calls I meant calls from the browser to the server.
> Right, in my case, now I may one call to get a list of news articles.
> One potential solution here would be to make the call to get the list
> of articles, then make another call to get the author for each
> article. I mentioned exponential growth because this method does grow
> faster depending on how many nested objects you have and on how many
> levels deep you have to go. Although one level grows pretty linearly O
> (1+n*m), where n is the number of top level Models, and m is the
> second level, it gets worse if you have to traverse further and
> further down the "rabbit hole", as in the case you mentioned where
> there would be multiple tiers. Luckily in my case I only have 1
> author per news article.
>
> I know this doesn't account for the DB side of things, but obviously
> it will pose the same problem. I would hope that the underlying
> framework could possibly take in account for this problem. I know in
> the Java world, Hibernate does something similar when you turn off
> lazy loading. The SQL that it generates for selects then attempts to
> do joins to make one single call to the back-end DB, where possible.
> Same for the deletes. From your statement, however, it doesn't seem
> like Django does this.
>
> I just wanted to get a general consensus on how people are tackling
> this in the real world, really. I am personally going to probably go
> the route of a custom serializer, probably something like
> this:http://wolfram.kriesing.de/blog/index.php/2007/json-serialization-for....
>
I have already written a customer serializer to just what you want.
You can find it at
http://wadofstuff.googlecode.com/svn/trunk/python/django/serializers
and can use it by adding to your settings.py:
SERIALIZATION_MODULES = {
'json': 'wadofstuff.django.serializers.json.Serializer'
}
Then in your code:
from django.core import serializers
serializers.serialize('json', NewsArticle.objects.all(), relations=
('author',))
This would give you the result you are after.
My module is 100% compatible with Django's for serialization but it
cannot yet deserialize JSON where you can followed related objects
such as in the example above.
regards
Matthew
--
http://wadofstuff.blogspot.com/
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---