ich hab folgende (noch) kleine klasse die zu sqlalchemy gemappt wird..
Code: Alles auswählen
class Tag(object):
def __init__(self, name):
self.name = name
@staticmethod
def add_tags_by_string(tag_string, entry):
# check for tag separator..
split_char = ',' if ',' in tag_string else ' '
tags = [ tag.strip() for tag in tag_string.split(split_char) ]
# check for already existing tags...
existant_tags = session.query(Tag).filter(Tag.name.in_(tags)).all()
existant_tag_names = [ tag.name for tag in existant_tags ]
not_exitant_tags = [ Tag(tag) for tag in tags if tag not in existant_tag_names ]
# create not existant tags...
session.add_all(not_exitant_tags)
session.flush()
# add all tags to the entry...
gruessle zero-one