Manoj Govindan wrote:
> 
> 
>> The serializer in trunk has a fields option, which only serializes the
>> fields supplied.
>>
>> Ex:
>> serializers.serialize('json', my_user_set, fields=('username', 'id'))
> 
> This doesn't work at the moment
> http://code.djangoproject.com/ticket/3466
> 
> But luckily there is also a patch ;)

Also, this isn't enough...

It would be better/cooler to be able to give "extra" fields and "fields 
you DON'T want". The extra could be a callback used on each item in the 
sequence:

# note, this is a pretty dumb example :-)
def generate_extra_user_data(user):
     return {
                "user_tags": [tag.name for tag in user.tag_set.all()],
                "username_uppercase": user.username.upper(),
            }

serializers.serialize('json',
        my_user_set,
        extra=generate_extra_user_data,
        hidden=["password", "email"])

Now one could go even one step further and add the 
generate_extra_user_data and 'hidden' to -for example- the Meta of your 
models and call it automatically from the serializer.


  - bram

--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to