A recent project used django Of xadmin Transform to do , There is little information about this , Now share what you have learned , Let's look it up when we need it .
1, classComm(Settings): Can be realized in
Add modules and secondary menus to the menu def get_nav_menu(self): menus = super(Comm, self).get_nav_menu() menus.append({ 'menus': [{ 'url': '/admin/report', 'icon': 'search', 'perm': 'main.view_record', 'title': ' Check the shift report ' }], 'first_icon': 'calendar', 'title': u' Check the shift report ' }) return menus Insert a secondary menu into the menu defget_nav_menu(self): model_dict1 = { 'url': '/cluster/index', 'icon': 'search', 'perm': 'main.view_record', 'title': ' survey ', } menus = super(Comm, self).get_nav_menu() menus[2]['menus'].insert(0, model_dict1) return menus Set the theme to choose enable_themes= True use_bootswatch = True Set system title site_title='** Pipe system ' Set menu style menu_style = 'accordion' Set the menu title of each module ,ps: This can also be accessed under modules __init__.py Add app_title= _(' User management ') apps_label_title = { 'auth':u' Rights management ', ‘user’:u’ User management ’ }
2,admin Query implementation
class PCAdmin(object): def open_detail(self,instance): return "<a href='http://***/%s' target='_blank'> details </a>" % instance.Host # Query filtering def get_list_queryset(self): return super(PCAdmin, self).get_list_queryset().filter(HomeId__in=[1,2]) open_detail.short_description = u'PC details ' open_detail.allow_tags = True open_detail.is_column = True # List display fields , list_display = ('Host','Type','Model', 'Cpu', 'Mem', 'Manager','open_detail') #open_detail Added custom redundant columns , Used to call the above function . show_detail_fields = ('Host')# Preview... In this field list_filter = ('ClusterId','Manager', 'Host')#filter Filter filter fields model_icon = 'laptop' # Displayed at the menu icon hidden_menu=True# Set not to display this module menu
3,model register
TYPE = ( (1, 'PC '), (2, ' The server ') ) class PCStatus(models.Model): Host =models.GenericIPAddressField('ip',max_length=20) # Dictionary type Type =models.IntegerField(' type ',choices=TYPE,blank=True,null=True) # Foreign key link HomeId=models.ForeignKey(HomeDict,verbose_name=’ The machine room ',db_column='HomeId',blank=True,null=True) Load = models.IntegerField(' Machine load ',blank=True,null=True) CheckTime = models.DateTimeField(' Monitoring time ',blank=True,null=True) class Meta: verbose_name = u" Machine analysis " verbose_name_plural = verbose_name def __unicode__(self): return "%s machine " % self.Host