On Wed, 2009-11-25 at 21:22 +0200, Nikolai Drozd wrote:
> Krishnakant wrote:
> > On Wed, 2009-11-25 at 21:00 +0200, Nikolai Drozd wrote:
> >>> from sqlalchemy.ext.declarative import declarative_base
> >>> base = declarative_base(meta.metadata)
> >> That seems to be correct. At least it works in my project :)
> >>
> > Then I believe it should be correct.
> > 
> >>> if Yes then how can I create instances of any table inside a control?
> >> What do you mean by instance of a table?
> > 
> > Ok here is a simple class which I created in my __init__.py file
> > in /model given the imports I am making specific to declarative_base. 
> > 
> > class members(base):
> >     __tablename__ = "person"
> >     id = sa.Column(sa.types.Integer, primary_key = True)
> >     membername = sa.Column(sa.types.String(250))
> >     address = sa.Column(sa.types.String(300))
> > 
> > Let's say in my control I want to add record to this table by getting
> > values from a request.
> 
> it may looks like this
> 
> from project_name.model.meta import Session
> 
> then somewhere in your code
> 
> m = members()
> m.membername = request.params['membername']
> m.address = request.params['address']
> 
> Session.add(m)
> Session.commit()
> 
> > Another method in the same control would like to query for all the
> > members in the table and send the result out as a c.records to be then
> > rendered into a mako template for form generation using for example
> > webhelpers.
> 
> to get all records:
> 
> Session.query(members).all( )
> 
> > 
> > My question is how can I use the above class to add records and how can
> > I query the table for records.
> 
> As far as I know all of these are described in documentation pretty well


Thanks, it worked for me.
when I passed the metadata instance created by my pylons application.

I think the pylons documentation sure need to be updated because the
information out there is incomplete when it comes to using declarative
syntax for table definition.

Happy hacking.
Krishnakant.


--

You received this message because you are subscribed to the Google Groups 
"pylons-discuss" 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/pylons-discuss?hl=en.


Reply via email to