class Organization(Model): name = Field() is_cover = Field('bool', default=False) @has_many() def admin_memberships3(self): return Membership.admins() has_many('memberships', {'users': { 'via': 'memberships' }}, {'admin_memberships': { 'target': 'Membership', 'scope': 'admins' }}, {'admins': { 'via': 'admin_memberships.user' }}, { 'admin_memberships2': { 'target': 'Membership', 'where': lambda m: m.role == 'admin' } }, {'admins2': { 'via': 'admin_memberships2.user' }}, {'admins3': { 'via': 'admin_memberships3.user' }})
class Person(Model): has_many('things', {'features': { 'via': 'things' }}, {'pets': 'Dog.owner'}, 'subscriptions') name = Field() age = Field('integer')
class Len(Model): a = Field() b = Field() c = Field() d = Field() validation = { 'a': { 'len': 5 }, 'b': { 'len': { 'gt': 4, 'lt': 13 } }, 'c': { 'len': { 'gte': 5, 'lte': 12 } }, 'd': { 'len': { 'range': (5, 13) } } }
class B(Model): tablename = "b" a = Field() b = Field(validation={'len': {'gte': 5}}) validation = {'a': {'len': {'gte': 5}}}
class Match(Model): a = Field() b = Field() validation = { 'a': {'match': 'ab'}, 'b': {'match': {'expression': 'ab', 'strict': True}} }
class Comment(Model): belongs_to('user', 'post') text = Field('text') date = Field('datetime') default_values = {'user': lambda: session.auth.user.id, 'date': now} validation = {'text': {'presence': True}} fields_rw = {'user': False, 'post': False, 'date': False}
class Post(Model): belongs_to('user') has_many('comments') title = Field() text = Field('text') date = Field('datetime') default_values = {'user': lambda: session.auth.user.id, 'date': now} validation = {'title': {'presence': True}, 'text': {'presence': True}} fields_rw = {'user': False, 'date': False}
class Thing(Model): belongs_to('person') name = Field() color = Field() uid = Field(unique=True) validation = { 'name': {'presence': True}, 'color': {'in': ['blue', 'red']}, 'uid': {'empty': False} }
class A(Model): tablename = "a" name = Field() val = Field('int') fval = Field('float') text = Field('text') password = Field('password') d = Field('date') t = Field('time') dt = Field('datetime') json = Field('json')
class Fortune(Model): tablename = "fortune" message = Field() @rowmethod('serialize') def _serialize(self, row): return {'id': row.id, 'message': row.message}
class World(Model): tablename = "world" randomnumber = Field('int') @rowmethod('serialize') def _serialize(self, row): return {'id': row.id, 'randomNumber': row.randomnumber}
class Consist(Model): email = Field() url = Field() ip = Field() image = Field.upload() emails = Field.string_list() emailsplit = Field.string_list() validation = { 'email': {'is': 'email'}, 'url': {'is': 'url'}, 'ip': {'is': 'ip'}, 'image': {'is': 'image'}, 'emails': {'is': 'list:email'}, 'emailsplit': {'is': {'list:email': {'splitter': ',;'}}} }
class Membership(Model): belongs_to('user', 'organization') role = Field() @scope('admins') def filter_admins(self): return self.role == 'admin'
class Proc(Model): a = Field() b = Field() c = Field() d = Field() e = Field.password() f = Field.password() validation = { 'a': {'lower': True}, 'b': {'upper': True}, 'c': {'clean': True}, 'd': {'urlify': True}, 'e': {'len': {'range': (6, 25)}, 'crypt': True}, 'f': {'len': {'gt': 5, 'lt': 25}, 'crypt': 'md5'} }
class Inside(Model): a = Field() b = Field.int() validation = { 'a': {'in': ['a', 'b']}, 'b': {'in': {'range': (1, 5)}} }
class Eq(Model): a = Field() b = Field('int') c = Field('float') validation = { 'a': { 'equals': 'asd' }, 'b': { 'equals': 2 }, 'c': { 'not': { 'equals': 2.4 } } }
class Subscription(Model): belongs_to('person') name = Field() status = Field('int') expires_at = Field('datetime') STATUS = {'active': 1, 'suspended': 2, 'other': 3} @scope('expired') def get_expired(self): return self.expires_at < datetime.now() @scope('of_status') def filter_status(self, *statuses): if len(statuses) == 1: return self.status == self.STATUS[statuses[0]] return self.status.belongs(*[self.STATUS[v] for v in statuses])
class Cost(Model): belongs_to('campaign') name = Field(notnull=True) date = Field.datetime(default=now) amount = Field.int() fields_rw = {"campaign": False, "date": False} validation = {'amount': {'gt': 1}}
class User(Model): name = Field() has_many('memberships', {'organizations': { 'via': 'memberships' }}, { 'cover_orgs': { 'via': 'memberships.organization', 'where': lambda m: m.is_cover == True } })
class Image(Model): belongs_to('user') has_many('comments') id = Field('text') title = Field('text') path = Field('text') comment = Field('text') date = Field('datetime') default_values = { 'user': lambda: session.auth.user.id, 'date': lambda: now } validation = { 'id': { 'presence': True }, } fields_rw = {'user': False, 'date': False}
class Elephant(Animal): belongs_to('mouse') color = Field() @rowattr('pretty') def get_pretty(self, row): return row.name + " " + row.color @before_insert def bi2(self, *args, **kwargs): pass
class Mixed(Model): belongs_to('person') date = Field.date() type = Field() inside = Field() number = Field.int() dont = Field() yep = Field() psw = Field.password() validation = { 'date': {'format': '%d/%m/%Y', 'gt': lambda: datetime.utcnow().date()}, 'type': {'in': ['a', 'b'], 'allow': None}, 'inside': {'in': ['asd', 'lol']}, 'number': {'allow': 'blank'}, 'dont': {'empty': True}, 'yep': {'presence': True}, 'psw': {'len': {'range': (6, 25)}, 'crypt': True} }
class A(Model): tablename = "a" name = Field() val = Field.int() fval = Field.float() text = Field.text() password = Field.password() d = Field.date() t = Field.time() dt = Field.datetime() json = Field.json()
class Campaign(Model): belongs_to('user') has_many('donations', 'costs') title = Field(notnull=True) description = Field(notnull=True) start = Field.datetime() end = Field.datetime() goal = Field.int() closed = Field.bool(default=True) fields_rw = {"user": False, "closed": False} validation = { "goal": { 'gt': 1 }, "start": { 'gt': now, 'format': "%d/%m/%Y %H:%M:%S" }, "end": { 'gt': now, 'format': "%d/%m/%Y %H:%M:%S" } } form_labels = {"title": T("Title: ")} @rowmethod('pledged') def get_pledge(self, row): summed = self.db.Donation.amount.sum() return row.donations(summed).first()[summed] or 0 @rowmethod('spended') def get_spended(self, row): summed = self.db.Cost.amount.sum() return row.costs(summed).first()[summed] or 0
class Animal(Model): belongs_to('zoo') name = Field() @rowattr('doublename') def get_double_name(self, row): return row.name * 2 @rowattr('pretty') def get_pretty(self, row): return row.name @before_insert def bi(self, *args, **kwargs): pass @before_insert def bi2(self, *args, **kwargs): pass
class StepOneThing(Model): name = Field() value = Field.float()
class StepFiveThing(Model): name = Field() value = Field.int() created_at = Field.datetime() indexes = {'name': True, ('name', 'value'): True}
class StepFourThingEdit(Model): tablename = "step_four_things" name = Field() value = Field.float() available = Field.bool(default=True) asd = Field.int()
class StepFourThing(Model): name = Field(notnull=True) value = Field.float(default=8.8) available = Field.bool(default=True) asd = Field()
class StepThreeThingThree(Model): tablename = "step_three_thing_ones" b = Field()