예제 #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)