def _set_tags(self, tags): if not tags: tags = [] if isinstance(tags, str) or isinstance(tags, unicode): tags = tags.split(",") if self.id: # ensure existing tag references are removed d = db.delete(post_tags, post_tags.c.post_id==self.id) db.engine.execute(d) valid_tags = [] for tag in tags: tag_obj = Tag.query.filter(Tag.id==tag).first() if tag_obj: tag_obj.posts.append(self) valid_tags.append(tag) self._tags = ','.join(tags)
def _set_tags(self, tags): self._tags = tags if self.id: # ensure existing tag references are removed d = db.delete(post_tags, post_tags.c.post_id==self.id) db.engine.execute(d) for tag in set(self.taglist): slug = slugify(tag) tag_obj = Tag.query.filter(Tag.slug==slug).first() if tag_obj is None: tag_obj = Tag(name=tag, slug=slug) db.session.add(tag_obj) tag_obj.posts.append(self)