But how would you actually add a tag? For example, say, using the example you provided below, I had a table called Document, which has is 'taggable'. If I create a Document object (doc1), I can see doc1.tags, which is a list. However, how do I actually _add_ a tag to doc1? I have a TagMixin object available in dir() but no Tag object (which I would have expected) - though a Tag class exists _inside_ the scope of the TagMixin. Do I have to create a Tag object outside the TagMixin class too?
On Thursday, 28 April 2011 00:59:59 UTC+2, Andrey Petrov wrote: > > Ah I was really close. This worked: > > > class TagMixin(object): > @declared_attr > def tags(cls): > class Tag(BaseModel): > __tablename__ = "tag_%s" % cls.__tablename__ > > id = Column(types.Integer, primary_key=True) > time_created = Column(types.DateTime, default=datetime.now, > nullable=False) > > row_id = Column(types.Integer, ForeignKey(cls.id), index=True) > name = Column(types.String, nullable=False, index=True) > > cls.TagClass = Tag > > return orm.relationship(Tag, backref='tagged') > > > > class User(BaseModel, TagMixin): > __tablename__ = 'user' > > id = Column(types.Integer, primary_key=True) > ... > > > -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To view this discussion on the web visit https://groups.google.com/d/msg/sqlalchemy/-/rSjfceG4OQEJ. 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/sqlalchemy?hl=en.
