ah, didn't know there was a technical name.  yes, i believe that is what 
i'm trying to do here.

i like to a degree the web2py DAL structure gearing more towards a 
"controller" class, but i would still like to have business objects as 
classes also, that will be acted upon by controller classes.

i just found the link below, and to mdipierro's point, i like and would 
want a Shop controller class that use DAL in a more efficient manner,  but 
i also think having all the logic related to an Order in Shop class might 
make it tough if there are any large underlying changes to Order, whereas a 
business object would make changes to the Order transparent to Shop.
https://groups.google.com/forum/#!msg/web2py/ro1CKfElZQI/4kQfmjrENt4J

so yea, i guess i'm wondering if there are any python/web2py magic that'll 
make database updates a bit easier.  tried to inherit from Storage but 
Table.<operation>() didn't like all the extra fields in the dictionary.

thanks,

tom


On Wednesday, November 14, 2012 10:04:54 AM UTC-5, viniciusban wrote:
>
> Are you trying to implement the Business Object pattern, Tom? 
>
>
>
> On Wed, Nov 14, 2012 at 12:54 PM, tom h <dark...@gmail.com <javascript:>> 
> wrote: 
> > hi, 
> > 
> > thanks i'll take a look at the hasattr(). 
> > 
> > that's not exactly what i mean.  the difference is having a model class 
> that 
> > represents a real-world application, vs using the Table class to make 
> > database updates.  in your example there, Product(1) is getting a record 
> > set, and to insert, one needs to explicit work with the Table object. 
> > 
> > i'd like to create a class that represents one specific product, and 
> have a 
> > easy way to save an instance of that class into the database. 
> > 
> > i've been reading this thread: 
> > 
> https://groups.google.com/forum/?fromgroups=#!searchin/web2py/web2py$20vs$20World/web2py/KgzKryAEIGw/pTMR_ZuZoJwJ
>  
> > 
> > i think their conclusion at the end is fairly close to what i'm trying 
> to 
> > do.  i was just wondering if there's a better way about it than how i've 
> > done it. 
> > 
> > thanks for your fast response. 
> > 
> > tom 
> > 
> > On Wednesday, November 14, 2012 7:01:34 AM UTC-5, viniciusban wrote: 
> >> 
> >> You may implement this getting your table fields and checking if your 
> >> class has this attribute with hasattr() (it's a Python builtin 
> >> function). It should be done in a upper level class, who you should 
> >> extend. 
> >> 
> >> But, maybe you're missing that DAL does exactly what you mean: this 
> >> mapping between your database physical fields and your properties. 
> >> 
> >> Maybe you could achieve that simply doing this: 
> >> >>> Product = db.define_table('product', ...) # all your define_table. 
> >> 
> >> From now on, you can do: 
> >> >>> p = Product(1) 
> >> >>> Product.price = 100 
> >> >>> Product.name = 'aaa' 
> >> >>> Product.update_or_insert() 
> >> 
> >> -- 
> >> Vinicius Assef 
> >> 
> >> 
> >> On Wed, Nov 14, 2012 at 6:09 AM, tom h <dark...@gmail.com> wrote: 
> >> > hi web2py gurus, 
> >> > 
> >> > just out of curiousity, i'd like to create a class (let's say 
> Product) 
> >> > that 
> >> > represents a record in my table "product".  right now, i can't figure 
> >> > out 
> >> > how to have the class attributes (p = Product(); p.price) saved to 
> the 
> >> > database without internally having p.__fields_dict__ containing ONLY 
> >> > table 
> >> > fields, and then map the p.price to p.__fields_dict__['price'], and 
> >> > finally 
> >> > doing something like p.db['product'].insert(p.__fields_dict__). 
> >> > 
> >> > i'm just wondering if there's any better way to do this, sorry i'm 
> >> > pretty 
> >> > new to Python as well and probably am missing something. 
> >> > 
> >> > ideally, i'd like something that's more like: 
> >> > 
> >> > p = Product(id=1) or Product() 
> >> > p.random_var = 'abc' 
> >> > p.name = 'a' 
> >> > p.price = 100.0 
> >> > p.save() # or db['product'].update_or_insert(p) 
> >> > 
> >> > thanks a lot! 
> >> > tom 
> >> > 
> >> > -- 
> >> > 
> >> > 
> >> > 
> > 
> > -- 
> > 
> > 
> > 
>

-- 



Reply via email to