class Person(Model): has_many('things', {'features': { 'via': 'things' }}, {'pets': 'Dog.owner'}, 'subscriptions') name = Field() age = Field.int()
class World(Model): tablename = "world" randomnumber = Field.int() @rowmethod('serialize') def _serialize(self, row): return {'id': row.id, 'randomNumber': row.randomnumber}
class Subscription(Signature): tablename = "subscriptions" subscription = Field.json() user_id = Field.int() defaulf_values = {'user_id': 0} @scope('by_user') def _by_user(self, user_id): return self.user_id == user_id
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 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 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 Sample(Model): str = Field() int = Field.int(default=0) float = Field.float(default=0.0)
class Sample(Model): str = Field() int = Field.int() float = Field.float() datetime = Field.datetime()
class Register(Model): value = Field.int()
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 Num(Model): a = Field.int() b = Field.int() c = Field.int() validation = {'a': {'gt': 0}, 'b': {'lt': 5}, 'c': {'gt': 0, 'lte': 4}}
class Inside(Model): a = Field() b = Field.int() validation = {'a': {'in': ['a', 'b']}, 'b': {'in': {'range': (1, 5)}}}
class Stuff(Model): a = Field.string() b = Field() price = Field.float() quantity = Field.int() total = Field.float() invisible = Field() validation = {"a": {'presence': True}} fields_rw = {"invisible": False} form_labels = {"a": "A label"} form_info = {"a": "A comment"} update_values = {"a": "a_update"} repr_values = {"a": _represent_f} form_widgets = {"a": _widget_f} # def setup(self): # self.table.b.requires = notInDb(self.db, self.table.b) @compute('total') def eval_total(self, row): return row.price * row.quantity @before_insert def bi(self, fields): return _call_bi(fields) @after_insert def ai(self, fields, id): return _call_ai(fields, id) @before_update def bu(self, set, fields): return _call_u(set, fields) @after_update def au(self, set, fields): return _call_u(set, fields) @before_delete def bd(self, set): return _call_d(set) @after_delete def ad(self, set): return _call_d(set) @rowattr('totalv') def eval_total_v(self, row): return row.price * row.quantity @rowmethod('totalm') def eval_total_m(self, row): return row.price * row.quantity @classmethod def method_test(cls, t): return cls.db, cls.table, t
class Price(Model): belongs_to('feature') value = Field.int()