[sqlalchemy] Can't get associated model and can't update it in MapperExtension?

2010-09-05 Thread Freewind
There are two classes: User and Question A user may have many questions, and it also contains a question_count to record the the count of questions belong to him. So, when I add a new question, I want update the question_count of the user. At first, I do as: question = Question(title='aaa',

[sqlalchemy] Re: Can't get associated model and can't update it in MapperExtension?

2010-09-05 Thread Freewind
, then update the associated user. If I write 'before_insert()' on user, it won't have chance to be invoked. On 9月6日, 上午2时05分, Michael Bayer mike...@zzzcomputing.com wrote: On Sep 5, 2010, at 1:27 PM, Freewind wrote: There are two classes: User and Question A user may have many

[sqlalchemy] Re: Can't get associated model and can't update it in MapperExtension?

2010-09-05 Thread Freewind
, then update the associated user. If I write 'before_insert()' on user, it won't have chance to be invoked. On 9月6日, 上午2时05分, Michael Bayer mike...@zzzcomputing.com wrote: On Sep 5, 2010, at 1:27 PM, Freewind wrote: There are two classes: User and Question A user may have many

[sqlalchemy] Re: Can't get associated model and can't update it in MapperExtension?

2010-09-05 Thread Freewind
Thank you, Mike! Your answer is really what I want to know, many thanks to you! On Sep 6, 5:17 am, Michael Bayer mike...@zzzcomputing.com wrote: On Sep 5, 2010, at 2:23 PM, Freewind wrote: I post the detail class here: Session = scoped_session(sessionmaker()) Base = declarative_base

[sqlalchemy] How to config Many-to-many with condition, in Sqlalchemy

2010-09-01 Thread Freewind
I'm use sqlalchemy 0.6.4. I have 2 classes: Question and Tag, they are many-to-many. {{{ class Question(Base): __tablename__ = questions id = Column(Integer, primary_key=True) deleted = Column(Boolean) ... tags = relationship('Tag', secondary=r_questions_tags) class

[sqlalchemy] How to select questions which have no answers

2010-09-01 Thread Freewind
I've two classes: Question and Answer. A question may have 0 or many answers. class Question(Base): __tablename__ = questions answers = relationship('Answer', backref='question', primaryjoin=Question.id==Answer.question_id) class Answer(Base): __tablename__ = answers Now I want to

[sqlalchemy] How to declare many-to-one in this example?

2010-08-23 Thread Freewind
I'm new to python(sqlalchemy), and I'm learning to build web site with pylons and sqlalchemy. I have a problem when I declare the relationship between models. I've tried it several hours, but failed. But I think it should be a basic question. I have two classes: User and Article, user can create