tags:

views:

80

answers:

1

Good day!

I'm learning Pylons web framework to create web UI for my database. Currently I'm exploring ways to declare my model. The most sexy way seems to be declarative with reflection. Can I use it with Pylons? (Because model/init.py states that I need to define reflection related staff inside init_model)

Thanks!

A: 

Are you using Pylons version 0.9.7? Pylons allrady stable at 1.0 version.

You can use declarative with reflection direct in model/init.py outside of init_model function. Or you can separate model definitions in any other modules or packages.

model/schema.py

from YOURAPP.model.meta import Base        # for declaration you models and reflection
from YOURAPP.model.meta import Session     # for using sa session object

class Category(Base):
    __tablename__ = 'category'

    id = Column(Integer, primary_key=True)
    name = Column(Unicode(70), index=True, unique=True)


    def __unicode__(self):
        return self.name


class Attribute(Base):
     __tablename__ = 'attribute'

    id = Column(Integer, primary_key=True)
    name = Column(Unicode(70), index=True)


    #Relation
    category_id = Column(Integer, ForeignKey('category.id'))
    category = relation(Category, backref=backref('attributes',
                    order_by=(name,))


    def __unicode__(self):
        return self.name

in model/init.py

from YOURAPP.model.schema import Category, Attribute
estin
0.9.7 because debian comes with 0.9.7 currently, and pylons book references 0.9.7 as well.In your example, you do not use *reflection* in any place. Please explain.
Zaar Hai