On Monday 27 November 2006 19:47, Oleg Broytmann wrote:
> On Mon, Nov 27, 2006 at 07:04:33PM +0100, Diez B. Roggisch wrote:
> > class User(SQLObjec):
> >      ...
> >
> >      def _init(self, *args, **kwargs):
> >            if <the_table_row_is_created>:
> >                  co_object = CoObject(userID=self.id)
> >            return super(User, self)._init(*args, **kwargs)
> >
> > This will ensure there is a CoObject whenever there is a User.
>
>    _init() is called during creation, so you can be sure the row has not
> been inserted into the DB yet, and there is no is. You need to change the
> order of operations:
>
>      def _init(self, *args, **kwargs):
>            super(User, self)._init(*args, **kwargs) # Perform INSERT and
> get the id co_object = CoObject(userID=self.id)

Ok, I tried your suggestion - this is the code:

class Guide(User):
    def _init(self, *args, **kwargs):
        super(Guide, self)._init(*args, **kwargs) # Perform INSERT and get the 
id
        user_name = self.user_name
        name = I18NText()
        name['en'] = user_name
        name['de'] = user_name
        description = I18NText()
        description['en'] = user_name
        description['de'] = user_name
        
        my_bookable = GuideBookable(handle=user_name, name=name, 
description=description,
                                    proportional_price=decimal.Decimal('0'),
                                    fixed_price=decimal.Decimal('0'),
                                    quantity=1,
                                    bookable_quantity=1,
                                    customer_visible=False,
                                    guideID = self.id
                                    )


Works fine for the first time. However, if I do for example

Guide.get(<the_id>)

I get an error like this:

model.py in _init(self, *args, **kwargs)
    383     def _init(self, *args, **kwargs):
    384         super(Guide, self)._init(*args, **kwargs) # Perform INSERT and 
get the id
--> 385         user_name = self.user_name
    386         name = I18NText()
    387         name['en'] = user_name


So - it seem _init is called on reloading the object as well, not only on 
creation time. Any suggestions?

-- 
>> Diez B. Roggisch
>> Developer

T  +49 (30) 443 50 99 - 27
F  +49 (30) 443 50 99 - 99
M  +49 (179) 11 75 303
E  [EMAIL PROTECTED]


>> artnology GmbH

A  Milastraße 4 / D-10437 Berlin
T  +49 (30) 443 50 99 - 0
F  +49 (30) 443 50 99 - 99
E  [EMAIL PROTECTED]
I  http://www.artnology.com

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
sqlobject-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss

Reply via email to