Skip to content
Browse files

A little bit of reformatting and renaming.

  • Loading branch information...
1 parent e2a20f4 commit 60c32247eb63bf2181f91bc73c8edc3c7529d0df @dnouri committed
Showing with 18 additions and 12 deletions.
  1. +17 −11 kotti/resources.py
  2. +1 −1 kotti/tests/test_tags.py
View
28 kotti/resources.py
@@ -250,13 +250,14 @@ def __repr__(self):
@property
def items(self):
- if getattr(self, 'content_tags', None) is not None:
- return [content_tag.items for content_tag in self.content_tags]
+ return [rel.item for rel in self.content_tags]
class TagsToContents(Base):
- tags_id = Column(Integer, ForeignKey('tags.id'), primary_key=True)
- contents_id = Column(Integer, ForeignKey('contents.id'), primary_key=True)
+ __tablename__ = 'tags_to_contents'
+
+ tag_id = Column(Integer, ForeignKey('tags.id'), primary_key=True)
+ content_id = Column(Integer, ForeignKey('contents.id'), primary_key=True)
tag = relation(Tag, backref=backref('content_tags', cascade='all'))
position = Column(Integer, nullable=False)
@@ -300,13 +301,18 @@ def __mapper_args__(cls):
creation_date = Column(DateTime())
modification_date = Column(DateTime())
in_navigation = Column(Boolean())
- _tags = relation(TagsToContents,
- backref=backref('items'),
- order_by=[TagsToContents.position],
- collection_class=ordering_list("position"),
- cascade='all, delete-orphan',
- )
- tags = association_proxy('_tags', 'tag_title', creator=TagsToContents._tag_find_or_create)
+ _tags = relation(
+ TagsToContents,
+ backref=backref('item'),
+ order_by=[TagsToContents.position],
+ collection_class=ordering_list("position"),
+ cascade='all, delete-orphan',
+ )
+ tags = association_proxy(
+ '_tags',
+ 'tag_title',
+ creator=TagsToContents._tag_find_or_create,
+ )
type_info = TypeInfo(
name=u'Content',
View
2 kotti/tests/test_tags.py
@@ -27,7 +27,7 @@ def test_add(self):
root = get_root()
root.tags = [u'tag 1', u'tag 2']
- result = DBSession.query(Tag).filter(TagsToContents.items == root).all()
+ result = DBSession.query(Tag).filter(TagsToContents.item == root).all()
assert result[0].items == [root]
assert root.tags == [u'tag 1', u'tag 2']
assert len(DBSession.query(Tag).all()) == 2

0 comments on commit 60c3224

Please sign in to comment.
Something went wrong with that request. Please try again.