#4656: Allow In-depth serialization by specifying depth to follow relationship
---------------------------------------------+------------------------------
          Reporter:  jay.m.mar...@gmail.com  |         Owner:  nobody  
            Status:  new                     |     Milestone:  post-1.0
         Component:  Serialization           |       Version:  SVN     
        Resolution:                          |      Keywords:  feature 
             Stage:  Accepted                |     Has_patch:  0       
        Needs_docs:  0                       |   Needs_tests:  0       
Needs_better_patch:  0                       |  
---------------------------------------------+------------------------------
Comment (by Matthew Flanagan <mattimust...@gmail.com>):

 Eric,

 Thanks for taking the time to look at it. I'll rework it as a patch on
 Django's own serializers but I wrote it as a standalone module that can be
 added to a project using the SERIALIZATION_MODULES setting so I didn't
 have to maintain it as a patch against Django trunk in my own projects.

 The extras functionality is a DRY thing for me e.g. putting things like
 get_absolute_url into JSON or other simple non-field properties/methods
 that I don't want to repeat the logic for in my templates. I'm using extjs
 grids for presenting data in an enterprise app and all the grid rows are
 populated with AJAX calls to a REST API using this serializer.

 The relations approach is based off how Rails does it. I'm not
 reimplementing the queryset api nor performng any filtering but specifying
 arguments to pass to subsequent calls to serialize() on each related or
 sub-related object. See handle_fk_field() in
 http://wadofstuff.googlecode.com/svn/trunk/python/django/serializers/python.py
 for gory details.

 For example

 {{{
 
relations={'permissions':{'relations':{'content_type':{'excludes':('app_label',)}
 }}}
 }}}

 Sort of breaks down to pseudocode to:
 {{{
    Serialize each permissions relation
         Serialize each content_type relation excluding the app_label field
 }}}

 I find exclusion very handy and quite succinct. Which would you prefer to
 write to exclude a User's password from being serialized:

 {{{
 serializers.serialize('json', User.objects.all(), excludes=('password',))
 }}}

 or

 {{{
 serializers.serialize('json', User.objects.all(), fields=('username',
 'first_name', 'last_name', 'email', 'is_staff', 'is_active',
 'is_superuser', 'last_login', 'date_joined', 'groups', 'user_permissions')
 }}}

-- 
Ticket URL: <http://code.djangoproject.com/ticket/4656#comment:9>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to