[web2py] Re: Conditional models

2012-05-14 Thread pbreit
Right now you can't have one model apply to two different controllers with conditional models. Copy/pasting should work but I would rarely advise that. Are you running into performance problems? Have you tried any other optimizations? 48 tables is kind of a lot but not crazy.

[web2py] Re: Conditional models

2012-05-15 Thread Annet
> Right now you can't have one model apply to two different controllers with > conditional models. Copy/pasting should work but I would rarely advise > that. Are you running into performance problems? No, but I read the posts in the group, and thought I'd better prevent running into performa

[web2py] Re: Conditional models

2012-05-15 Thread Cliff
You must be very careful about multiple copies of table definitions. Only one copy can be allowed to migrate the table. Upgrading the tables in a production environment is tedious. First you must upgrade the models independent of the controllers, then use the admin app to ensure all the migrat

[web2py] Re: Conditional models

2012-05-15 Thread pbreit
"I'd better prevent running into performance problems" I generally advise against premature optimization.

Re: [web2py] Re: Conditional models

2012-05-15 Thread Bruno Rocha
put you table definitions on modules and use conditional models to instantiate them. http://zerp.ly/rochacbruno Em 15/05/2012 05:44, "Annet" escreveu: > > Right now you can't have one model apply to two different controllers with >> conditional models. Copy/pasting should work but I would rarely

Re: [web2py] Re: Conditional models

2012-05-15 Thread Annet
I too think Bruno has the right answer, however, when it comes to Python programming I am not yet proficient enough to translate my model files into modules and use conditional models to instantiate them :-( I hope one of you can provide me with a working example that I can explore. Kind regar

Re: [web2py] Re: Conditional models

2012-05-15 Thread howesc
there are some (complex) examples of models in modules floating around the group. the simple suggestion bruno made would look something like this: module/mytable.py def init(): current.myapp.db.define_table() return then in your conditional model file: current.myapp.db= db #get the db conn

Re: [web2py] Re: Conditional models

2012-05-15 Thread Bruce Wade
Not sure using conditional models is "premature optimization" it is just better design. On Tue, May 15, 2012 at 12:14 PM, pbreit wrote: > "I'd better prevent running into performance problems" > > I generally advise against premature optimization. > -- -- Regards, Bruce Wade http://ca.linke

Re: [web2py] Re: Conditional models

2012-05-15 Thread Bruno Rocha
*# models/db.py* ... db = DAL(".") ... *# modules/datamodels/myobject.py* from gluon import current from gluon.dal import Field class MyObject(object): def __init__(seld, db): self.db = db self.T = current.T self.request = current.request self.fields = [

Re: [web2py] Re: Conditional models

2012-05-15 Thread pbreit
Bruno mentioned modules, not conditional models.

Re: [web2py] Re: Conditional models

2012-05-15 Thread Bruno Rocha
Better example: *# models/db.py* ... db = DAL(".") ... *# modules/datamodels/base.py* class BaseModel(object): def define_table(self): self.db.define_table(self.tablename, *self.fields, **self.params) *# modules/datamodels/dog.py* from gluon import current from gluon.dal import

Re: [web2py] Re: Conditional models

2012-05-15 Thread Bruce Wade
These examples are only good if you have 1 model per class. I prefer the design used in Auth with a define_tables method. On Tue, May 15, 2012 at 12:41 PM, Bruno Rocha wrote: > Better example: > > > *# models/db.py* > ... > db = DAL(".") > ... > > *# modules/datamodels/base.py* > > class Bas

Re: [web2py] Re: Conditional models

2012-05-15 Thread Cliff
Bruce, Maybe I'm a little simple minded today ... Could you give an example where you would have more than one model per class? On Tuesday, May 15, 2012 3:43:33 PM UTC-4, Bruce Wade wrote: > > These examples are only good if you have 1 model per class. I prefer the > design used in Auth with a

Re: [web2py] Re: Conditional models

2012-05-15 Thread Bruno Rocha
I am looking in to it, and realized that there ia a better, simple and more elegant way. In Django models, it is very commom to use a subclass named Meta, so I will try to run something like. class Dog(BaseModel): self.name = Field("name") self.guardian = Field("guardian", "reference g

Re: [web2py] Re: Conditional models

2012-05-15 Thread Bruce Wade
Well one example is my location class, which contains countries, provinces, and cities models. Having one class allows me to write a single API that is self contained and very modular to handle any location related task. On Tue, May 15, 2012 at 1:35 PM, Bruno Rocha wrote: > I am looking in to it

Re: [web2py] Re: Conditional models

2012-05-15 Thread Bruce Wade
For example see attached, it isn't complete but will give a better example. On Tue, May 15, 2012 at 1:43 PM, Bruce Wade wrote: > Well one example is my location class, which contains countries, > provinces, and cities models. Having one class allows me to write a single > API that is self conta

Re: [web2py] Re: Conditional models

2012-05-15 Thread Anthony
And just to be clear, defining models in modules and defining modules using classes are two independent design decisions -- you can use classes even in regular model files, and you can use modules without using classes. If you want, you can just use regular functions in modules: */modules/mymod

Re: [web2py] Re: Conditional models

2012-05-15 Thread Anthony
> > class MyObject(object): > def __init__(seld, db): > self.db = db > self.T = current.T > self.request = current.request > > self.fields = [ > Field("field1", label=self.T("Foo")), > Field("field2), > >

Re: [web2py] Re: Conditional models

2012-05-15 Thread Annet
Thank you all for providing me with examples of how to put my model into modules. They're very helpful to get me started on this subject. Kind regards, Annet.

[web2py] Re: conditional models requires check if table already exists for db admin to work

2012-07-03 Thread Anthony
Doesn't seem like a great idea to be repeating table definitions. Maybe you should put this one in a non-conditional model file, or define it in a module and do an import. Anthony On Tuesday, July 3, 2012 6:33:28 AM UTC-4, selecta wrote: > > In my project I use conditional models since I have a