Massimo OK - I have taken both your comments on board with the twist that I have:
- for now, kept my classes in a separate file from db.py as I can see both files getting largish and unwieldy - time will tell - my db.py imports my classes file and thus makes it visible to all the controllers Just for info, I have decided to re-engineer in web2py a commercial site I developed for a customer. As well as the normal data capture and display, it involves creating reports, generating emails, linking to a secure payment server and a memory cache to speed up complex searches so I see it as a good test - not so much of web2py but more does the framework work for me. I am going to log the time it takes and any significant techniques. I'll let you know the results. It will take a little time as it will be a "screensaver" task :-) On Oct 8, 4:19 pm, mdipierro <[EMAIL PROTECTED]> wrote: > Excellent point and idea. > > If the class is general (not specifically tied to one table) that you > should put it in a module, so that more apps can use it. If this is > specific for a table in one app, I would put it in the model that > defines the table, so you do not need to import it and it will be > visible by all controllers in the app. > > Attention that you should not name a table "user" because some > database engines consider it a reserver sql keyword. > > Massimo > > On Oct 8, 6:46 am, billf <[EMAIL PROTECTED]> wrote: > > > As I keep saying, I'm a newbie to web2py and python coming from a Java > > background. Some things that I do as "standard" are not described in > > examples so I would like some advice, i.e. should I still be doing X > > and if so how? > > > My app has a "user" table and in Java I would have a class to hold the > > data and methods with an associated class to handle persistence. In > > web2py, the associated class is replaced by the DAL which is great. > > However, encapsulating "user" related methods in a class still seems > > "a good thing". Is it? > > > My first instinct is to create a User class with an optional __init__ > > argument to allow creation from the db so that I can do something > > like: > > results=db(db.user.id=id).select() > > if len(results)==1: > > user=User(results[0]) > > else: > > user=User() > > > The User class contains various methods, etc. To test this, I just > > put the class code in the controller but I plan to have several > > controllers all of which could reference User. > > > Should the class be put into a module perhaps with other similar > > classes (Animal, Vet, etc)? > > > Where is the preferred location for such application related class and/ > > or module files? > > > Am I missing anything else? > > > Bill --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "web2py Web Framework" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/web2py?hl=en -~----------~----~----~----~------~----~------~--~---

