def register(self, model_class, admin_class=None): """ 注册表: site.register(models.CustomerInfo,CustomerAdmin) :param model_class: models.CustomerInfo :param admin_class: CustomerAdmin model_class._meta.app_label = models.CustomerInfo._meta.app_label :获取对应APP名称 model_class._meta.model_name = models.CustomerInfo._meta.model_name :获取对应表名称 """ app_name = model_class._meta.app_label model_name = model_class._meta.model_name if not admin_class: # 为了避免多个model共享同一个BaseKingAdmin内存对象 # 实例化BaseKingAdmin对象,每一次循环此语句都开辟一块新内存 admin_class = BaseKingAdmin() else: # 实例化 CustomerAdmin 对象 admin_class = admin_class() admin_class.model = model_class # 把model_class赋值给了admin_class if app_name not in self.enabled_admins: self.enabled_admins[app_name] = {} # enabled_admins中存的是字典(字典中套字典):crm:{ {'CustomerInfo':'CustomerAdmin'} , {'Role':'RoleAdmin'}} # enabled_admins[crm][CustomerInfo] = CustomerAdmin self.enabled_admins[app_name][model_name] = admin_class
def register(self, model_class, admin_class=None): app_name = model_class._meta.app_label model_name = model_class._meta.model_name if not admin_class: admin_obj = BaseKingAdmin() else: admin_obj = admin_class() admin_obj.model = model_class if app_name not in self.enable_admin: self.enable_admin[app_name] = {} self.enable_admin[app_name][model_name] = admin_obj
def register(self,models_class,admin_class=None): app_name = models_class._meta.app_label #获取该model所属的app名 model_name = models_class._meta.model_name #获取该model的类名 if not admin_class: admin_class = BaseKingAdmin() else: admin_class = admin_class() admin_class.model = models_class if app_name not in self.enabled_admins: self.enabled_admins[app_name] = {} self.enabled_admins[app_name][model_name] = admin_class
def register(self, model_class, admin_class=BaseKingAdmin): """注册admin表""" # print(model_class,admin_class) app_name = model_class._meta.app_label model_name = model_class._meta.model_name if not admin_class: #为了避免多个admin_class共享同一个BaseKingAdmin对象,要实例化 admin_class = BaseKingAdmin() else: admin_class = admin_class() admin_class.model = model_class #把model_class赋值给了admin_class if app_name not in self.enable_admins: self.enable_admins[app_name] = {} self.enable_admins[app_name][model_name] = admin_class
def register(self, model_class, admin_class=None): """注册admin表""" app_name = model_class._meta.app_label model_name = model_class._meta.model_name if not admin_class: #为了避免多个model共享一个BaseKingAdmin内存对象 admin_class = BaseKingAdmin() else: admin_class = admin_class() admin_class.model = model_class #把model_class赋值给了admin_class if app_name not in self.enabled_admins: self.enabled_admins[app_name] = {} self.enabled_admins[app_name][model_name] = admin_class
def register(self, model_class, admin_class=None): '''注册admin表''' app_name = model_class._meta.app_label #获取app name model_name = model_class._meta.model_name #获取表名 if admin_class is None: admin_class = BaseKingAdmin() #变成实例 else: admin_class = admin_class() #变成实例 admin_class.model = model_class #将 admin_class 和它的 model 类 关联起来,如果没有定义,则默认为BaseKingAdmin if app_name not in self.enable_admins: self.enable_admins[app_name] = {} self.enable_admins[app_name][model_name] = admin_class
def register(self, model_class, admin_class=None): '''注册ADMIN''' print('register', model_class, admin_class) app_name = model_class._meta.app_label model_name = model_class._meta.model_name if not admin_class: #避免多个model 共享同一个BaseKingadmin admin_class = BaseKingAdmin() else: admin_class = admin_class() admin_class.model = model_class #把models_class赋值给admin_class if app_name not in self.enabled_admins: self.enabled_admins[app_name] = {} self.enabled_admins[app_name][model_name] = admin_class
def register(self,model_class,admin_class=BaseKingAdmin): '''注册admin表''' # print('register',model_class,admin_class) #获取app名字 app_name = model_class._meta.app_label #获取表名 model_name = model_class._meta.model_name if not admin_class: admin_class = BaseKingAdmin() else: admin_class = admin_class() admin_class.model = model_class if app_name not in self.enable_admins: self.enable_admins[app_name] = {} self.enable_admins[app_name][model_name] = admin_class
def register(self, model_class, admin_class=None): """注册admin表""" # print(model_class, admin_class) app_name = model_class._meta.app_label #crm model_name = model_class._meta.model_name #小写类名 # print(app_name, model_name) if not admin_class: #为了避免多个model共享同一个BaseKingAdmin内存对象 admin_class = BaseKingAdmin() else: admin_class = admin_class() admin_class.model = model_class #把model_class赋值给admin_class if app_name not in self.enabled_admins: self.enabled_admins[app_name] = {} self.enabled_admins[app_name][model_name] = admin_class
def register(self, model_class, admin_class=None): '''注册admin表''' # print('register',model_class,admin_class) #获取app名字 app_name = model_class._meta.app_label #获取表名 model_name = model_class._meta.model_name #把model_class赋值给了admin_class,然后在视图中可以通过admin_class找到对应的model类(表名字) if not admin_class: # 实例化,如果没写注册的类,就用BaseKingAdmin admin_class = BaseKingAdmin() else: #如果写了注册的类,就实例化自己 admin_class = admin_class() admin_class.model = model_class if app_name not in self.enable_admins: self.enable_admins[app_name] = {} self.enable_admins[app_name][model_name] = admin_class
def register(self,model_class,admin_class=None): '''注册admin表''' # print('register',model_class,admin_class) #获取app名字 app_name = model_class._meta.app_label #获取表名 model_name = model_class._meta.model_name #把model_class赋值给了admin_class,然后在视图中可以通过admin_class找到对应的model类(表名字) if not admin_class: # 实例化,如果没写注册的类,就用BaseKingAdmin admin_class = BaseKingAdmin() else: #如果写了注册的类,就实例化自己 admin_class = admin_class() admin_class.model = model_class if app_name not in self.enable_admins: self.enable_admins[app_name] = {} self.enable_admins[app_name][model_name] = admin_class
def register(self, model_class, admin_class=None): """ 注册 admin models" :param model_class: 数据表名 :param admin_class: 自定制的类名 :return: """ app_name = model_class._meta.app_label # crm models.UserProfile._meta.app_label model_name = model_class._meta.model_name # userprofile models.UserProfile._meta.model_name # 如果没有定义自定制的 admin 样式类,就用默认的样式类 if not admin_class: admin_class = BaseKingAdmin() # 如果有自定制的 admin 样式类,就用自定制的 else: admin_class = admin_class() # 如:UserProfileAdmin() admin_class.model = model_class # 把 model_class 赋值给 admin_class if app_name not in self.enabled_admins: self.enabled_admins[app_name] = {} self.enabled_admins[app_name][model_name] = admin_class