예제 #1
0
 def set_model(self, model):
     if issubclass(model, models.ModelBase):
         self.model = model
     elif isinstance(model, six.string_types):
         app, model = model.split('.')
         self.model = get_model(app, model)
         if not self.model:
             raise AttributeError('Model `%s.%s` not found.' % (app, model))
     else:
         raise AttributeError('Model must be subclass of models.Model or string: `app.model`.')
예제 #2
0
 def set_manager(self, manager):
     if isinstance(manager, models.Manager):
         self.manager = manager
         self.model = manager.model
     elif isinstance(manager, six.string_types):
         app, model, manager = manager.split('.')
         self.model = get_model(app, model)
         if not self.model:
             raise AttributeError('Model `%s.%s` not found.' % (app, model))
         self.manager = getattr(self.model, manager)
     elif not manager and self.model:
         self.manager = self.model._default_manager
     else:
         raise AttributeError('First set manager for filter')