예제 #1
0
    def set_model_object(self, model):

        if isinstance(model, basestring):
            self.set_lazy(True)
            # ok, it is a string, so I got to look for it in the
            # registry
            if "." in model:
                items = model.split(".")
                dots = len(items)
                if dots == 2:
                    # got the app_label
                    app_label, classname = items
                    model = ModelRegistry.get_model(app_label, classname)
                else:  # more than 2 dots
                    # got the module name
                    modulename = ".".join(items[:-1])
                    classname = items[-1]
                    model = [m for m in \
                             ModelRegistry.get_all(by_module=modulename) \
                             if m.__name__ == classname][0]

            elif model == 'self':
                self.set_self_referenced(True)

        if not self.is_lazy and not hasattr(model, '__dead_parrot__'):
            raise TypeError, "%r is not a valid model" % model

        self.model = model
        if not self.is_lazy:
            self.set_to_model(model)
예제 #2
0
    def set_model_object(self, model):

        if isinstance(model, basestring):
            self.set_lazy(True)
            # ok, it is a string, so I got to look for it in the
            # registry
            if "." in model:
                items = model.split(".")
                dots = len(items)
                if dots == 2:
                    # got the app_label
                    app_label, classname = items
                    model = ModelRegistry.get_model(app_label, classname)
                else: # more than 2 dots
                    # got the module name
                    modulename = ".".join(items[:-1])
                    classname = items[-1]
                    model = [m for m in \
                             ModelRegistry.get_all(by_module=modulename) \
                             if m.__name__ == classname][0]

            elif model == 'self':
                self.set_self_referenced(True)

        if not self.is_lazy and not hasattr(model, '__dead_parrot__'):
            raise TypeError, "%r is not a valid model" % model

        self.model = model
        if not self.is_lazy:
            self.set_to_model(model)
예제 #3
0
    def resolve(self):
        model_list = ModelRegistry.get_all(by_class=self.model)
        if model_list:
            self.model = model_list[0]
        else:
            err = 'The model %r does not exist or is ' \
                  'not registered, did you import it ?'
            raise AttributeError(err % self.model)

        self.set_to_model(self.model)
        self.set_lazy(False)
예제 #4
0
    def resolve(self):
        model_list = ModelRegistry.get_all(by_class=self.model)
        if model_list:
            self.model = model_list[0]
        else:
            err = 'The model %r does not exist or is ' \
                  'not registered, did you import it ?'
            raise AttributeError(err % self.model)

        self.set_to_model(self.model)
        self.set_lazy(False)