Thanks, it finally worked. Following your suggestion, what I did is: 1. in class body, define: content = db.BlobProperty(required=False) # notice required is set to False
2. in __init__(arg1, arg2, ...): self.content = '' Then self.content += src doesn't complain anymore. When accessing, it returns a db.Blog doesn't sound too foreign to me. For now, I just think it as a customized type caster in C++. But I am facing another problem now, I will post it in a new thread 'Different behavior in Debug run'. Regards, Will On Tue, Jan 27, 2009 at 8:31 PM, Alexander Kojevnikov < alexan...@kojevnikov.com> wrote: > > When creating an UploadStorage entity, you should initialise the > content property: > > my_entity = UploadStorage(content='') > > or: > > my_entity = UploadStorage() > my_entity.content = '' # or whatever your initial value is > > I know, it a bit confusing. When you define the property in the class, > UploadStorage.content is an instance of db.BlobProperty. > > But when you access it after the entity is created, it returns the > actual value of the property, which is of db.Blob type (subclass of > str). > > > On Jan 27, 10:13 pm, Will <vocalster....@gmail.com> wrote: > > I rewrote it, now the error message became > > > > unsupported operand type(s) for +=: 'NoneType' and 'str' > > > > pointing at > > > > self.content += src > > > > Seems *content* was not constructed in modified __init__. If I added > > > > self.content = db.BlobProperty(required=True) > > > > into __init__ while keeping the definition in the class body, I got > > > > Property content must be convertible to a Blob instance (Blob() argument > > should be str instance, not BlobProperty) > > > > Seems this time* content* was constructed but in __init__() somehow it > > wanted to initialize it by a Blob instance, not BlobProperty?! > > > > Will > > > > On Tue, Jan 27, 2009 at 6:43 PM, Alexander Kojevnikov < > > > > alexan...@kojevnikov.com> wrote: > > > > > Rewrite your UploadStorage class to declare the module properties in > > > the class body, not in the __init__ method. App Engine forwards access > > > to property definitions to the actual property values, creation of the > > > properties in __init__ is probably not compatible with it. > > > > > For example, when you access self.content in your append() method, GAE > > > returns the value of the append property, not the property definition. > > > > > Try this code: > > > > > class UploadStorage(db.Model): > > > content = db.BlobProperty(required=True) > > > last_change = db.DateTimeProperty(required=True, auto_now=True) > > > field_name = db.StringProperty(required=True, default=u'') > > > ...... > > > > > def __init__(self, field_name, file_name, content_type, > > > content_length, charset): > > > if field_name: > > > self.field_name = field_name > > > > > def append(self, src): > > > self.content += src > > > > > On Jan 27, 9:25 pm, Will <vocalster....@gmail.com> wrote: > > > > Here you go, > > > > > > ------------------------------ > > > > class UploadStorage(db.Model): > > > > def __init__(self, field_name, file_name, content_type, > > > content_length, > > > > charset): > > > > self.content = db.BlobProperty(required=True) > > > > self.last_change = db.DateTimeProperty(required=True, > > > auto_now=True) > > > > self.field_name = db.StringProperty(required=True, > default=u'') > > > > ...... > > > > > > if (field_name): > > > > self.field_name = field_name > > > > > > def append(self, src): > > > > self.content += src > > > > ------------------------------------- > > > > class GAEUploadedFile(UploadedFile): > > > > def __init__(self, field_name, file_name, content_type, > > > content_length, > > > > charset): > > > > self.__storage = UploadStorage(field_name, file_name, > > > content_type, > > > > content_length, charset) > > > > ...... > > > > > > def write(self, content): # append > > > > self.__storage.append(content) > > > > self.size = len(self.__storage.content) > > > > > > Thanks, > > > > > > Will > > > > > > On Tue, Jan 27, 2009 at 7:47 AM, Alexander Kojevnikov < > > > > > > alexan...@kojevnikov.com> wrote: > > > > > > > > No, doesn't work. I got > > > > > > > > unsupported operand type(s) for +=: 'BlobProperty' and 'str' > > > > > > > > Same as before. > > > > > > > Could you post here all related code, including the construction of > a > > > > > Storage entity? > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Google App Engine" group. To post to this group, send email to google-appengine@googlegroups.com To unsubscribe from this group, send email to google-appengine+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en -~----------~----~----~----~------~----~------~--~---