程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Application of xadmin project based on Django

編輯:Python

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


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved