Djangoベースxadminプロジェクト応用


最近のプロジェクトはdjangoのxadminを改造して、この方面の資料は少し少なくて、今自分で学んだことを分かち合って、一回みんなが使う時に調べます. 
1,classComm(Settings):で実装可能
            
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': '    '
           }],
           'first_icon': 'calendar',
           'title': u'    '
       })
       return menus
            
   defget_nav_menu(self):
       model_dict1 = {
                'url': '/cluster/index',
                'icon': 'search',
                'perm': 'main.view_record',
                'title': '  ',
       }
 
       menus = super(Comm, self).get_nav_menu()
       menus[2]['menus'].insert(0, model_dict1)
       return menus
 
 
 
               
        enable_themes= True
        use_bootswatch = True
             
        site_title='**   '
             
        menu_style = 'accordion'
          ,ps:            __init__.py   app_title= _('    ')
 apps_label_title = {
           'auth':u'    ',
           ‘user’:u’    ’
     }

   
2,adminクエリー実装
 
class  PCAdmin(object):
     
     def open_detail(self,instance):
         return  "<a href='http://***/%s' target='_blank'>  </a>" % instance.Host
     #    
def get_list_queryset(self):
         return super(PCAdmin, self).get_list_queryset().filter(HomeId__in=[1,2])
     open_detail.short_description = u'PC  '
     open_detail.allow_tags = True
     open_detail.is_column = True
#      ,
     list_display = ('Host','Type','Model', 'Cpu', 'Mem', 'Manager','open_detail') #open_detail         ,        。
     show_detail_fields = ('Host')#       
     list_filter = ('ClusterId','Manager', 'Host')#filter       
     model_icon = 'laptop' #      icon
     hidden_menu=True#          

3,モデル登録
TYPE = (
    (1, 'PC '),
   (2, '   ')
)
class  PCStatus(models.Model):
Host =models.GenericIPAddressField('ip',max_length=20)
#    
Type =models.IntegerField('  ',choices=TYPE,blank=True,null=True)
#    
HomeId=models.ForeignKey(HomeDict,verbose_name=’
     ',db_column='HomeId',blank=True,null=True)
   Load = models.IntegerField('    ',blank=True,null=True)
   CheckTime = models.DateTimeField('    ',blank=True,null=True)
   class Meta:
       verbose_name = u"    "
       verbose_name_plural = verbose_name
 
   def __unicode__(self):
       return "%s   " % self.Host