Esempio n. 1
0
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)
Esempio n. 2
0
class Dog(GenericObject):
    additional_properties = True
    fields = {
        "name": StringField(),
        "owner": ReferenceTo(NAMESPACE, "person", cascade_delete=True)
    }

    def talk(self):
        return "woof"
Esempio n. 3
0
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")
Esempio n. 4
0
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
Esempio n. 5
0
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}'
Esempio n. 6
0
class Fish(GenericObject):

    fields = {
        "name": StringField(),
        "location": LatLongField(),
        "born": DateTimeField(),
        "length": DecimalField(),
        "edible_fraction": FractionField(),
        "image": BytesField()
    }
Esempio n. 7
0
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)
Esempio n. 8
0
class Person(GenericObject):
    fields = {
        "name": StringField(),
        "dogs": ReferenceFrom(NAMESPACE, "dog", "owner_id")
    }
Esempio n. 9
0
class Monkey(GenericObject):
    use_rev = False
    fields = {
        "name": StringField(),
        "colour": StringField(immutable=True),
    }
Esempio n. 10
0
class House(GenericObject):

    fields = {
        "name": StringField(),
        "location": LatLongField(),
    }
Esempio n. 11
0
class Fence(GenericObject):

    fields = {"name": StringField(), "boundary": ListField()}