2015-10-13 87 views
0

我正在自定義我的管理頁面,並且在訪問django.contrib.admin.AdminSite方法時遇到了一些問題。我是新來的Django所以你要容易,如果我我的錯誤是愚蠢的繼承AdminSite但無法訪問父類中的get_app_list(對象沒有屬性'get_app_list')

在這裏,我嘗試在我admin.py

class MyAdmin(admin.AdminSite): 
    @never_cache 
    def index(self, request, extra_context=None): 
     """ 
     Displays the main admin index page, which lists all of the installed 
     apps that have been registered in this site. 
     """ 
     app_list = super(MyAdmin, self).get_app_list(request) 

     context = dict(
      self.each_context(request), 
      title=self.index_title, 
      app_list=app_list, 
     ) 
     context.update(extra_context or {}) 

     request.current_app = super(MyAdmin, self).name 

     return TemplateResponse(request, super(MyAdmin, self).index_template or 
           'admin/testing.html', context) 

admin_site = MyAdmin(name='myadmin') 

延長AdminSite並覆蓋index我也試圖保持

self.get_app_list(request)

但都給了我同樣的問題

AttributeError的在/ myadmin/'超級' 對象沒有屬性 'get_app_list'

AttributeError的在/ myadmin/'自我' 對象沒有屬性 'get_app_list'

我已經用適當的設置更改了我的urls.pysettings.py

任何幫助深表感謝

回答

1

不知道你在哪裏得到這個想法,但是看一下源代碼,get_app_list輔助方法,在Django 1.9中引入的。

以下是指向源代碼的鏈接。

而且很顯然,它看起來像你使用Django < = 1.8.5

+0

你得到它,謝謝! – bobleujr