#设置主题 admin配置
class BaseSetting:
enable_themes=True
use_bootswatch=True
xadmin.site.register(views.BaseAdminView,BaseSetting)
#添加表格-models-更新数据库
class IDC(models.Model):
name=models.CharField(max_length=30,verbose_name='服务器名称')
desc = models.CharField(max_length=100, verbose_name='服务器介绍')
phone = models.CharField(max_length=30, verbose_name='联系方式')
address = models.CharField(max_length=130, verbose_name='所在地址')
create_time=models.DateTimeField(auto_now=True,verbose_name='创建时间')
#配置admin-分页-搜索
@xadmin.sites.register(IDC)
class IDCAdmin:
list_display=('name','desc','phone','address','create_time')
search_fields=('name',)
list_per_page=2
search_fields=('name',)
list_per_page=2
#操作员写入-models-更新数据库
class IDC(models.Model):
name=models.CharField(max_length=30,verbose_name='服务器名称')
desc = models.CharField(max_length=100, verbose_name='服务器介绍')
phone = models.CharField(max_length=30, verbose_name='联系方式')
address = models.CharField(max_length=130, verbose_name='所在地址')
create_time=models.DateTimeField(auto_now=True,verbose_name='创建时间')
user=models.ForeignKey(User,on_delete=models.CASCADE,editable=False,null=True,verbose_name='操作员')
class Meta:
verbose_name='IDE管理'
verbose_name_plural=verbose_name
#admin配置
@xadmin.sites.register(IDC)
class IDCAdmin:
list_display=('name','desc','phone','address','create_time','user')
search_fields=('name',)
list_per_page=2
def save_models(self):
self.new_obj.user=self.request.user
super().save_models()
转载于:https://my.oschina.net/u/4036782/blog/2978893