Re: json serialization without certain fields and with extra information?

2007-03-10 Thread shevken
Hey guys, How do you de-serialize the object back at the ajax response. class Cart(models.Model): ... def get_total_quantity(): return quantity; self.response = self.xmlhttp.responseText; // parse the response into a JSON object var json_data = self.response.parseJSON(); alert(jso

Re: json serialization without certain fields and with extra information?

2007-03-04 Thread Manoj Govindan
Hi Bram, Here is a possible mechanism to address your second point, i.e., hide certain fields while serializing. Consider this model: class Person(models.Model): ... # various fields here. @staticmethod def fields_for_serializing(): return [list of those field names that can

Re: json serialization without certain fields and with extra information?

2007-03-01 Thread Bram - Smartelectronix
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 luc

Re: json serialization without certain fields and with extra information?

2007-02-28 Thread Manoj Govindan
> 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 ;) Regards, M

Re: json serialization without certain fields and with extra information?

2007-02-28 Thread Deryck Hodge
On 2/28/07, Bram - Smartelectronix <[EMAIL PROTECTED]> wrote: > > hey everyone, > > > 1. is there any way to serialize models and remove some fields? I.e. I > would like to serialize User for example, but I definitely don't want > the email to be there. > The serializer in trunk has a fields opti

Re: json serialization without certain fields and with extra information?

2007-02-28 Thread limodou
My code will seem like: def _get_data(request, obj): if obj.icon: icon = '' % (obj.get_icon_url(), obj.title) else: icon = '' % obj.title authors = [x.username for x in obj.authors.all()] return ({'id':obj.id, 'icon':icon, 'title':obj.title, 'description':o

Re: json serialization without certain fields and with extra information?

2007-02-28 Thread Bram - Smartelectronix
limodou wrote: > django also uses simplejson to dump python variable, why you want to > avoid it? And I think using simplejson is more flexiable and simple. Because it's more generic and I don't want to recreate what's done in the models... In the end I did it like this: # MODEL --

Re: json serialization without certain fields and with extra information?

2007-02-28 Thread limodou
On 2/28/07, Bram - Smartelectronix <[EMAIL PROTECTED]> wrote: > > limodou wrote: > > On 2/28/07, Bram - Smartelectronix <[EMAIL PROTECTED]> wrote: > >> hey everyone, > >> > >> > >> 1. is there any way to serialize models and remove some fields? I.e. I > >> would like to serialize User for example,

Re: json serialization without certain fields and with extra information?

2007-02-28 Thread Bram - Smartelectronix
limodou wrote: > On 2/28/07, Bram - Smartelectronix <[EMAIL PROTECTED]> wrote: >> hey everyone, >> >> >> 1. is there any way to serialize models and remove some fields? I.e. I >> would like to serialize User for example, but I definitely don't want >> the email to be there. >> >> 2. is there a way

Re: json serialization without certain fields and with extra information?

2007-02-28 Thread limodou
On 2/28/07, Bram - Smartelectronix <[EMAIL PROTECTED]> wrote: > > hey everyone, > > > 1. is there any way to serialize models and remove some fields? I.e. I > would like to serialize User for example, but I definitely don't want > the email to be there. > > 2. is there a way to provide "custom" pa

json serialization without certain fields and with extra information?

2007-02-28 Thread Bram - Smartelectronix
hey everyone, 1. is there any way to serialize models and remove some fields? I.e. I would like to serialize User for example, but I definitely don't want the email to be there. 2. is there a way to provide "custom" parts of the serialization? For example, when serializing a Book I would lik