所以,我在我的一个类中创建了一个JSON返回属性,但是在尝试使用其中一个属性时出现错误:
class Posts(Base):
__tablename__ = 'posts'
post_id = Column(Integer, nullable = False, primary_key = True)
text = Column(String, nullable = False)
date = Column(DateTime(timezone=True), server_default=func.now())
deleted = Column(Integer, default = 0)
owner = Column(Integer, ForeignKey('users.id'))
owner_rel = relationship('Users')
comments_rel = relationship('Comments', cascade='all, delete-orphan', lazy='dynamic')
@property
def serialize(self):
# Returns Data Object In Proper Format
return {
'postID': self.post_id,
'text': self.text,
'date': self.date,
'owner': self.owner,
'postOwner': self.owner_rel.serialize,
'comments': self.comments_rel.serialize
}
class Comments(Base):
__tablename__ = 'comments'
comment_id = Column(Integer, nullable = False, primary_key = True)
post_id = Column(Integer, ForeignKey('posts.post_id'))
post_rel = relationship('Posts')
text = Column(String, nullable = False)
date = Column(DateTime(timezone=True), server_default=func.now())
deleted = Column(Integer, default = 0)
owner = Column(Integer, ForeignKey('users.id'))
owner_rel = relationship('Users')
@property
def serialize(self):
# Returns Data Object In Proper Format
return {
'commentID': self.comment_id,
'postID': self.post_id,
'text': self.text,
'date': self.date,
'ownerID': self.owner,
'owner': self.owner_rel.serialize
}
我得到了这个错误 - ' AppenderQuery'对象没有属性'序列化'
帮助?