Workout With Friends
Stay fit with a little motivation
 All Classes Namespaces Files Functions Variables Properties
meta.py
Go to the documentation of this file.
1 from __future__ import unicode_literals
2 from sqlalchemy.ext.declarative import declarative_base
3 from sqlalchemy.orm import scoped_session, sessionmaker
4 from wowf.lib.fulltext import FulltextBase
5 from zope.sqlalchemy import ZopeTransactionExtension
6 
7 
8 DBSession = scoped_session(sessionmaker(extension=ZopeTransactionExtension()))
9 
10 
12 
13  query = DBSession.query_property()
14 
15  def __str__(self):
16  return unicode(self).encode('utf-8')
17 
18  def __repr__(self):
19  return repr(unicode(self))
20 
21  def __unicode__(self):
22  return self.__class__.__name__
23 
24  @classmethod
25  def get_by_id(cls, id):
26  return cls.query.get(id)
27 
28  @classmethod
29  def create(cls, **kwargs):
30  obj = cls(**kwargs)
31  DBSession.add(obj)
32  DBSession.flush()
33  return obj
34 
35  def delete(self):
36  DBSession.delete(self)
37 
38 
39 Base = declarative_base(cls=Base)
40