def post(self): """Create tag.""" data = TagSchema().deserialize(request.json) tag_exists = db_session.query(exists().where( Tag.name == data['name'] )).scalar() if tag_exists: abort(409) tag = Tag() tag.name = data['name'] db_session.add(tag) db_session.commit() return jsonify(id=tag.id)
def post(self, **kwargs): """Create entry.""" data = AddEntrySchema().deserialize(request.json) entry = Entry() entry.amount = data['amount'] entry.date = data['date'] entry.setoptattr('note', data['note']) if data['tags']: entry.tags = Tag.query.filter(Tag.id.in_(data['tags'])).all() db_session.add(entry) db_session.commit() resp = {'id': entry.id} d = data['totalForMonth'] if d is not None: resp['totalAmount'] = '%.2f' % (Entry.month_total(d) or 0) return jsonify(**resp)