Skip to content

Commit

Permalink
Changed the execution slightly.
Browse files Browse the repository at this point in the history
  • Loading branch information
bunnyblanco committed May 29, 2015
1 parent a98320f commit 50a128f
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion chicagothree/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,17 @@ def create_schema(session):
Base.metadata.create_all()

def add_tag(tname, session):
"""
Add a unique tag to the database. Returns the associated tag_id
"""
q = session.query(Tag.id).filter_by(name=tname)
if session.query(literal(True)).filter(q.exists()).scalar():
tag_id = q.value(Tag.id)
else:
tg = Tag(name=tname)
session.add(tg)
session.commit()
tag_id = tg.id
session.commit()
return tag_id

def add_tagid_option(tagopt, session):
Expand Down

0 comments on commit 50a128f

Please sign in to comment.