def _set_tags(self, tags): self._tags = tags if self.id: # ensure existing tag references are removed d = db.delete(question_tags, question_tags.c.question_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) if self not in tag_obj.question: tag_obj.question.append(self)
def _set_name(self, name): self._name = name.lower().strip() self.slug = slugify(name)