Esempio n. 1
0
    def save(self):
        """
        Saves the model instance to the database (blocking), unlike insert() this is an instance method so needs to be called by
        and instantiated model instance::

            from models import MyTestModel

            my_data = {
                    'this_field':       "Hello World",
                    'another_field':    42,
                    'whatever_field':   True
                  }

            model_instance = MyTestModel(my_data)
            model_instance.save()

        """
        from Mojo.ServerHelpers.RunServer import BACKEND_COLLECTION, DATABASE

        if DATABASE:
            if BACKEND_COLLECTION:
                this_collection = BACKEND_COLLECTION(DATABASE, self)
                self.validate()
                ret_obj = this_collection.save(self)

                return ret_obj
Esempio n. 2
0
    def save(self):
        """
        Saves the model instance to the database (blocking), unlike insert() this is an instance method so needs to be called by
        and instantiated model instance::

            from models import MyTestModel

            my_data = {
                    'this_field':       "Hello World",
                    'another_field':    42,
                    'whatever_field':   True
                  }

            model_instance = MyTestModel(my_data)
            model_instance.save()

        """
        from Mojo.ServerHelpers.RunServer import BACKEND_COLLECTION, DATABASE

        if DATABASE:
            if BACKEND_COLLECTION:
                this_collection = BACKEND_COLLECTION(DATABASE, self)
                self.validate()
                ret_obj = this_collection.save(self)

                return ret_obj