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
-~----------~----~----~----~------~----~------~--~---

Reply via email to