Re: problems deserializing json object

2010-01-06 Thread Malcolm MacKinnon
Thanks Daniel, I'll give that a try.

On Wed, Jan 6, 2010 at 2:02 AM, Daniel Roseman wrote:

> On Jan 6, 1:54 am, Malcolm MacKinnon  wrote:
> > I'm having difficulty deserializing a json object. I'm using django
> > appengine patch, so the models aren't the same as django's, but they are
> > very similar:
> >
> > class Cust(db.Model):
> > custno = db.StringProperty(required=True)
> > company = db.StringProperty(required=True)
> > contact = db.StringProperty(required=False)
> > address1 = db.StringProperty(required=False)
> > address2 = db.StringProperty(required=False)
> > city = db.StringProperty(required=True)
> > state = db.StringProperty(required=False)
> > zipc = db.StringProperty(required=False)
> > country = db.StringProperty(required=False)
> > phone = db.StringProperty(required=False)
> > salesmn = db.StringProperty(required=True)
> > email = db.StringProperty()
> >
> > def __unicode__(self):
> > return self.custno + " : " + str(self.company)+" :
> > "+str(self.city)+" : "+str(self.state)
>
> Aargh! unicode methods must return unicode! Not bytestrings! Do this:
> return u'%s: %s: %s: %s' % (self.custno, self.company, self.city,
> self.state)
>
>
> >
> > class Cust_List(db.Model):
> > custno = db.StringProperty(required=True)
> > companies = db.TextProperty(required=True) #customer list as json
> object
> >
> > Note that the json object is stored in the db.TextProperty companies, and
> is
> > composed of more than a 1000 customers, all of which are also
> individually
> > stored in the model, Cust . I query the json object for a customer list,
> > since it saves CPU time on the appengine.
> >
> > Here's what happens when I try to decode the json string object:>>> from
> sport.models import Cust_List
> > >>> from django.core import serializers
> > >>> a=Cust_List.all()
> > >>> b=a.get() #returns the only and only data item in this model, which
> is a
> >
> > json object previously stored in the datastore.>>>
> c=serializers.deserialize('json', b.companies)
> > >>> d=list(c)
> > >>> e=len(d)
> > >>> e
> > 1057
> > >>> b
> >
> > etc...
> > cy...@global.net", "phone": "269/552-", "state": "MN", "contact":
> "Rick
> > L
> > ee", "salesmn": "O1", "country": "", "address2": ""}}, {"pk": "XBwTAxc
> > hELEgpzcG9ydGNUYDA", "model": "sport.cust", "fields": {"city": "GOLD RIVE
> > R", "zipc": "95670", "address1": "11282 PYRITES WAY", "company":
> "ZSPORTS",
> > "cus
> > tno": "ZSP001", "email": "ra...@zsports.com", "phone": "916/638-0033",
> "sta
> > te": "CA", "contact": "Randy Mintz", "salesmn": "H1", "country": "",
> > "address2":
> >  ""}}]')>>> d
> >
> > etc...
> >  ,
> >  > edObject: WAT091 : WATERVILLE VALLEY RESORT : WATERVILLE VALLEY : NH>,
> >  > izedObject: WES003 : WESTCHESTER ROAD RUNNER : WHITE PLAINS : NY>,
> >  > Object: WES100 : WEST HILL SHOP : PUTNEY : VT>,  WHE189
> > : WH
> > EELIE FUN MULTI SPORT : LEBANON : OH>,  > WHIRLAWAY S
> > PORTS CTR : METHUEN : MA>,  > TOURING
> >  : DAVIS : WV>,  :
> > WHIS
> > TLER, BC : >,  > CO>,  > eserializedObject: WIL520 : WILD ROSE MOUNTAIN SPORTS : SALT LAKE CITY :
> > UT>,  > eserializedObject: WIL659 : ADVENTURE OUTFITTERS : HADLEY : MA>,
> >  > ject: WIL760 : WILDERNESS WAY, INC : SOLDOTNA : AK>,  > WIL9LA
> >  : WILSON BACKCOUNTRY : WILSON : WY>,  WILSON
> > MOUNT
> > AIN SPORTS : LAKE LOUISE, ALBERTA : >,  > WILDERNESS
> > SPORTS-DILLON : DILLON : CO>,  > MOUNTAIN SP
> > ORTS : WINTHROP : WA>,  > LAKE C
> > ITY : UT>,  WILMINGTON :
> > DE>
> > ,  BURLINGTON
> > : V
> > T>,  VT>,
> >  > erializedObject: WOR059 : WORLD CYCLE : BOISE : ID>,  > YEL017
> >  : YELLOWSTONE GATEWAY SPORTS : BOZEMAN : MT>,  ZAP013 :
> > ZAP
> > POS.COM : HENDERSON : NV>,  > PALO AL
> > TO : CA>,  KALAMAZOO :
> > MI>
> > , ] etc.
> >
> > Note that I just get returned a unicode representation of my model, Cust.
> > But the contact information, address information, and so on disappears in
> > the deserialized object. Any thoughts on why or what I'm doing wrong?
> >
> > Thanks for any help or ideas!
> >
> You're not getting a unicode representation, you're getting a
> DeserialzedObject. As the documentation (http://docs.djangoproject.com/
> en/1.1/topics/serialization/#deserializing-data) says, you need to
> iterate through the list of objects and call save() on each one to
> create the actual model.
> --
> DR.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@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.
>
>
>
>
-- 

You received this message because you are subscribed to the Google Groups "Django users" group.

To post to this group, send email to django-us...@googlegroups.com.

To unsubscribe from this group, send email to django-users+uns

Re: problems deserializing json object

2010-01-06 Thread Daniel Roseman
On Jan 6, 1:54 am, Malcolm MacKinnon  wrote:
> I'm having difficulty deserializing a json object. I'm using django
> appengine patch, so the models aren't the same as django's, but they are
> very similar:
>
> class Cust(db.Model):
>     custno = db.StringProperty(required=True)
>     company = db.StringProperty(required=True)
>     contact = db.StringProperty(required=False)
>     address1 = db.StringProperty(required=False)
>     address2 = db.StringProperty(required=False)
>     city = db.StringProperty(required=True)
>     state = db.StringProperty(required=False)
>     zipc = db.StringProperty(required=False)
>     country = db.StringProperty(required=False)
>     phone = db.StringProperty(required=False)
>     salesmn = db.StringProperty(required=True)
>     email = db.StringProperty()
>
>     def __unicode__(self):
>         return self.custno + " : " + str(self.company)+" :
> "+str(self.city)+" : "+str(self.state)

Aargh! unicode methods must return unicode! Not bytestrings! Do this:
return u'%s: %s: %s: %s' % (self.custno, self.company, self.city,
self.state)


>
> class Cust_List(db.Model):
>     custno = db.StringProperty(required=True)
>     companies = db.TextProperty(required=True) #customer list as json object
>
> Note that the json object is stored in the db.TextProperty companies, and is
> composed of more than a 1000 customers, all of which are also individually
> stored in the model, Cust . I query the json object for a customer list,
> since it saves CPU time on the appengine.
>
> Here's what happens when I try to decode the json string object:>>> from 
> sport.models import Cust_List
> >>> from django.core import serializers
> >>> a=Cust_List.all()
> >>> b=a.get() #returns the only and only data item in this model, which is a
>
> json object previously stored in the datastore.>>> 
> c=serializers.deserialize('json', b.companies)
> >>> d=list(c)
> >>> e=len(d)
> >>> e
> 1057
> >>> b
>
> etc...
> cy...@global.net", "phone": "269/552-", "state": "MN", "contact": "Rick
> L
> ee", "salesmn": "O1", "country": "", "address2": ""}}, {"pk": "XBwTAxc
> hELEgpzcG9ydGNUYDA", "model": "sport.cust", "fields": {"city": "GOLD RIVE
> R", "zipc": "95670", "address1": "11282 PYRITES WAY", "company": "ZSPORTS",
> "cus
> tno": "ZSP001", "email": "ra...@zsports.com", "phone": "916/638-0033", "sta
> te": "CA", "contact": "Randy Mintz", "salesmn": "H1", "country": "",
> "address2":
>  ""}}]')>>> d
>
> etc...
>  ,
>  edObject: WAT091 : WATERVILLE VALLEY RESORT : WATERVILLE VALLEY : NH>,
>  izedObject: WES003 : WESTCHESTER ROAD RUNNER : WHITE PLAINS : NY>,
>  Object: WES100 : WEST HILL SHOP : PUTNEY : VT>,  : WH
> EELIE FUN MULTI SPORT : LEBANON : OH>,  WHIRLAWAY S
> PORTS CTR : METHUEN : MA>,  TOURING
>  : DAVIS : WV>,  WHIS
> TLER, BC : >,  CO>,  eserializedObject: WIL520 : WILD ROSE MOUNTAIN SPORTS : SALT LAKE CITY :
> UT>,  eserializedObject: WIL659 : ADVENTURE OUTFITTERS : HADLEY : MA>,
>  ject: WIL760 : WILDERNESS WAY, INC : SOLDOTNA : AK>,  WIL9LA
>  : WILSON BACKCOUNTRY : WILSON : WY>,  MOUNT
> AIN SPORTS : LAKE LOUISE, ALBERTA : >,  WILDERNESS
> SPORTS-DILLON : DILLON : CO>,  MOUNTAIN SP
> ORTS : WINTHROP : WA>,  LAKE C
> ITY : UT>,  DE>
> ,  : V
> T>, ,
>  erializedObject: WOR059 : WORLD CYCLE : BOISE : ID>,  YEL017
>  : YELLOWSTONE GATEWAY SPORTS : BOZEMAN : MT>,  ZAP
> POS.COM : HENDERSON : NV>,  PALO AL
> TO : CA>,  MI>
> , ] etc.
>
> Note that I just get returned a unicode representation of my model, Cust.
> But the contact information, address information, and so on disappears in
> the deserialized object. Any thoughts on why or what I'm doing wrong?
>
> Thanks for any help or ideas!
>
You're not getting a unicode representation, you're getting a
DeserialzedObject. As the documentation (http://docs.djangoproject.com/
en/1.1/topics/serialization/#deserializing-data) says, you need to
iterate through the list of objects and call save() on each one to
create the actual model.
--
DR.
-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.




Problems deserializing json object

2010-01-05 Thread Mac
I'm having difficulty deserializing a json object. I'm using django
appengine patch, so the models aren't the same as django's, but they
are very similar:

class Cust(db.Model):
custno = db.StringProperty(required=True)
company = db.StringProperty(required=True)
contact = db.StringProperty(required=False)
address1 = db.StringProperty(required=False)
address2 = db.StringProperty(required=False)
city = db.StringProperty(required=True)
state = db.StringProperty(required=False)
zipc = db.StringProperty(required=False)
country = db.StringProperty(required=False)
phone = db.StringProperty(required=False)
salesmn = db.StringProperty(required=True)
email = db.StringProperty()

def __unicode__(self):
return self.custno + " : " + str(self.company)+" : "+str
(self.city)+" : "+str(self.state)

class Cust_List(db.Model):
custno = db.StringProperty(required=True)
companies = db.TextProperty(required=True) #customer list as json
object

Note that the json object is stored in the db.TextProperty companies,
and is composed of more than a 1000 customers, all of which are also
individually stored in the model, Cust . I query the json object for a
customer list, since it saves CPU time on the appengine.

Here's what happens when I try to decode the json string object:
>>> from sport.models import Cust_List
>>> from django.core import serializers
>>> a=Cust_List.all()
>>> b=a.get() #returns the only and only data item in this model, which is a 
>>> json object previously stored in the datastore.
>>> c=serializers.deserialize('json', b.companies)
>>> d=list(c)
>>> e=len(d)
>>> e
1057
>>> b
etc...
cy...@global.net", "phone": "269/552-", "state": "MN", "contact":
"Rick L
ee", "salesmn": "O1", "country": "", "address2": ""}}, {"pk": "XBwTAxc
hELEgpzcG9ydGNUYDA", "model": "sport.cust", "fields": {"city": "GOLD
RIVE
R", "zipc": "95670", "address1": "11282 PYRITES WAY", "company":
"ZSPORTS", "cus
tno": "ZSP001", "email": "ra...@zsports.com", "phone": "916/638-0033",
"sta
te": "CA", "contact": "Randy Mintz", "salesmn": "H1", "country": "",
"address2":
 ""}}]')
>>> d
etc...
 ,
,
,
, , , , , , , ,
,
, , , , , 
, , , ,
, , , 
, ] etc.

Note that I just get returned a unicode representation of my model,
Cust. But the contact information, address information, and so on
disappears in the deserialized object. Any thoughts on why or what I'm
doing wrong?

Thanks for any help or ideas!
>>>
-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.




problems deserializing json object

2010-01-05 Thread Malcolm MacKinnon
I'm having difficulty deserializing a json object. I'm using django
appengine patch, so the models aren't the same as django's, but they are
very similar:

class Cust(db.Model):
custno = db.StringProperty(required=True)
company = db.StringProperty(required=True)
contact = db.StringProperty(required=False)
address1 = db.StringProperty(required=False)
address2 = db.StringProperty(required=False)
city = db.StringProperty(required=True)
state = db.StringProperty(required=False)
zipc = db.StringProperty(required=False)
country = db.StringProperty(required=False)
phone = db.StringProperty(required=False)
salesmn = db.StringProperty(required=True)
email = db.StringProperty()

def __unicode__(self):
return self.custno + " : " + str(self.company)+" :
"+str(self.city)+" : "+str(self.state)

class Cust_List(db.Model):
custno = db.StringProperty(required=True)
companies = db.TextProperty(required=True) #customer list as json object

Note that the json object is stored in the db.TextProperty companies, and is
composed of more than a 1000 customers, all of which are also individually
stored in the model, Cust . I query the json object for a customer list,
since it saves CPU time on the appengine.

Here's what happens when I try to decode the json string object:
>>> from sport.models import Cust_List
>>> from django.core import serializers
>>> a=Cust_List.all()
>>> b=a.get() #returns the only and only data item in this model, which is a
json object previously stored in the datastore.
>>> c=serializers.deserialize('json', b.companies)
>>> d=list(c)
>>> e=len(d)
>>> e
1057
>>> b
etc...
cy...@global.net", "phone": "269/552-", "state": "MN", "contact": "Rick
L
ee", "salesmn": "O1", "country": "", "address2": ""}}, {"pk": "XBwTAxc
hELEgpzcG9ydGNUYDA", "model": "sport.cust", "fields": {"city": "GOLD RIVE
R", "zipc": "95670", "address1": "11282 PYRITES WAY", "company": "ZSPORTS",
"cus
tno": "ZSP001", "email": "ra...@zsports.com", "phone": "916/638-0033", "sta
te": "CA", "contact": "Randy Mintz", "salesmn": "H1", "country": "",
"address2":
 ""}}]')
>>> d
etc...
 ,
,
,
, , , , , , , ,
, , , , , , 
, , ,
, , , , 
, ] etc.

Note that I just get returned a unicode representation of my model, Cust.
But the contact information, address information, and so on disappears in
the deserialized object. Any thoughts on why or what I'm doing wrong?

Thanks for any help or ideas!
>>>
-- 

You received this message because you are subscribed to the Google Groups "Django users" group.

To post to this group, send email to django-us...@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.