Thanks Daniel, I'll give that a try. On Wed, Jan 6, 2010 at 2:02 AM, Daniel Roseman <dan...@roseman.org.uk>wrote:
> On Jan 6, 1:54 am, Malcolm MacKinnon <mmack3...@gmail.com> 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-0000", "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... > > <DeserializedObject: WAS160 : WASATCH RUNNING CENTER : SANDY : UT>, > > <Deserializ > > edObject: WAT091 : WATERVILLE VALLEY RESORT : WATERVILLE VALLEY : NH>, > > <Deserial > > izedObject: WES003 : WESTCHESTER ROAD RUNNER : WHITE PLAINS : NY>, > > <Deserialized > > Object: WES100 : WEST HILL SHOP : PUTNEY : VT>, <DeserializedObject: > WHE189 > > : WH > > EELIE FUN MULTI SPORT : LEBANON : OH>, <DeserializedObject: WHI002 : > > WHIRLAWAY S > > PORTS CTR : METHUEN : MA>, <DeserializedObject: WHI296 : WHITE GRASS SKI > > TOURING > > : DAVIS : WV>, <DeserializedObject: WHI443 : WHISTLER XC SKI & HIKE LTD. > : > > WHIS > > TLER, BC : >, <DeserializedObject: WIL490 : WILDERNESS SPORTS : DILLON : > > CO>, <D > > eserializedObject: WIL520 : WILD ROSE MOUNTAIN SPORTS : SALT LAKE CITY : > > UT>, <D > > eserializedObject: WIL659 : ADVENTURE OUTFITTERS : HADLEY : MA>, > > <DeserializedOb > > ject: WIL760 : WILDERNESS WAY, INC : SOLDOTNA : AK>, <DeserializedObject: > > WIL9LA > > : WILSON BACKCOUNTRY : WILSON : WY>, <DeserializedObject: WIL9TM : > WILSON > > MOUNT > > AIN SPORTS : LAKE LOUISE, ALBERTA : >, <DeserializedObject: WIL9TQ : > > WILDERNESS > > SPORTS-DILLON : DILLON : CO>, <DeserializedObject: WIN106 : WINTHROP > > MOUNTAIN SP > > ORTS : WINTHROP : WA>, <DeserializedObject: WIN361 : WINTERSTEIGER : SALT > > LAKE C > > ITY : UT>, <DeserializedObject: WOM001 : WOMEN'S SPORTS SPEC. : > WILMINGTON : > > DE> > > , <DeserializedObject: WOM016 : WOMEN'S SOURCE FOR SPORTS : SOUTH > BURLINGTON > > : V > > T>, <DeserializedObject: WOO155 : WOODSTOCK INN & RESORT : WOODSTOCK : > VT>, > > <Des > > erializedObject: WOR059 : WORLD CYCLE : BOISE : ID>, <DeserializedObject: > > YEL017 > > : YELLOWSTONE GATEWAY SPORTS : BOZEMAN : MT>, <DeserializedObject: > ZAP013 : > > ZAP > > POS.COM : HENDERSON : NV>, <DeserializedObject: ZOM004 : ZOMBIE RUNNER : > > PALO AL > > TO : CA>, <DeserializedObject: ZOO005 : ZOO CITY CYCLE & SPORT : > KALAMAZOO : > > MI> > > , <DeserializedObject: ZSP001 : ZSPORTS : GOLD RIVER : CA>] 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<django-users%2bunsubscr...@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+unsubscr...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.