Django will this view shown in the admin index
Will this view shown as a link in admin index in a portion called modules? Which user can click on the link like normal admin class to view the view?
I have a class in called ListAdmin in Admin.py:
class ListAdmin(admin.ModelAdmin):
def list_view(self, request):
return question_list(request)
def get_urls(self):
urls = super(ListAdmin, self).get_urls()
list_urls = patterns('', r'^list/$', self.list_view())
return list_urls + urls
The view is in view.py
def question_list(request):
#questions = Question.objects.filter(topic__icontains = 1)
questions = Question.objects.all()
return render_to_response('admin/question_list.html', {'questions':questions})
question_list = staff开发者_开发知识库_member_required(question_list)
The problem is I don't know how to register the ListAdmin into the admin, because it does not have a list model, and the Question model is already registered.
admin.site.register(???, ListAdmin)
The possible solution is this:
Multiple ModelAdmins/views for same model in Django admin
I added this into my admin.py, it succesfully added a link into the admin index:
class List(Question):
class Meta:
proxy = True
class ListAdmin(QuestionAdmin):
def list_view(self, request):
return question_list(request)
admin.site.register(List, ListAdmin)
I still think that it is wrong because if I take the line below out from the url.py, it will direct to the Question model:
url(r'^admin/modules/list/$', 'exam.admin.modules.views.question_list'),
精彩评论