class Cat(GenericObject): fields = { "name": StringField(), "colour": StringField(immutable=True), "tail": BoolField(immutable=True, default=True), "legs": NumberField(required=True), "owner_id": ReferenceTo(NAMESPACE, "person", required=True), } @classmethod def all_with_n_legs(cls, db, legs): return db.view("animal_views/cat_legs", key=legs)
class Dog(GenericObject): additional_properties = True fields = { "name": StringField(), "owner": ReferenceTo(NAMESPACE, "person", cascade_delete=True) } def talk(self): return "woof"
class Dog(GenericObject): additional_properties = True sync_gateway_write = True fields = { "name": StringField(), "colour": StringField(), "owner_id": ReferenceTo(NAMESPACE, "person", cascade_delete=True), "kennel_club_membership": StringField(unique=True), "channels": ListField(default=["callbacks"]) } def talk(self): return "woof" def changes_cb(self, db, queue, new=False): if self.owner: self.owner.add_callback(db, "changes_cb")
class User(FamObject): use_rev = False additional_properties = False fields = { '_id': NumberField(), 'name': StringField(), 'phone': StringField(), 'email': StringField(), 'birth': DateTimeField(), } def get_user_data(self): return f'{self.name} - {self.phone} - {self.email} - {self.birth}' def pre_save_new_cb(self, obj): print(self) print('something after save') return True
class Event(FamObject): use_rev = False additional_properties = False fields = { '_id': NumberField(), 'state': StringField(), } def get_calls_data(self): return f'{self.req} - {self.date}'
class Fish(GenericObject): fields = { "name": StringField(), "location": LatLongField(), "born": DateTimeField(), "length": DecimalField(), "edible_fraction": FractionField(), "image": BytesField() }
class Person(GenericObject): fields = { "name": StringField(), "cats": ReferenceFrom(NAMESPACE, "cat", "owner_id", cascade_delete=True), "dogs": ReferenceFrom(NAMESPACE, "dog", "owner_id"), "animals": ReferenceFrom(NAMESPACE, ["dog", "cat"], "owner_id"), "callbacks": ListField() } def add_callback(self, db, name): if self.callbacks is None: self.callbacks = [] self.callbacks.append(name) self.save(db)
class Person(GenericObject): fields = { "name": StringField(), "dogs": ReferenceFrom(NAMESPACE, "dog", "owner_id") }
class Monkey(GenericObject): use_rev = False fields = { "name": StringField(), "colour": StringField(immutable=True), }
class House(GenericObject): fields = { "name": StringField(), "location": LatLongField(), }
class Fence(GenericObject): fields = {"name": StringField(), "boundary": ListField()}