Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django custom view into admin page

I have created a custom view.

How can I insert the view into the admin?

For a normal admin class, we can just simply register it to the admin site:

class ListAdmin(admin.ModelAdmin):    ...  admin.site.register(List, ListAdmin) 

I tried to override get_url in admin.py, question_list is the view:

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  admin.site.register(question_list, ListAdmin) 

This is the question_list view:

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) 

I get 'function' object is not iterable error.

Thanks.

like image 825
kelvin Avatar asked Apr 17 '11 12:04

kelvin


People also ask

Is it possible to create a custom admin view without a model behind it?

The most straightforward answer is "no". As the Django Book says, the admin is for "Trusted users editing structured content," in this case the structured content being models arranged in hierarchies and configured through settings.py.

Can I use Django admin as frontend?

Django's Docs clearly state that Django Admin is not made for frontend work.

How do I get to the admin page in Django?

To login to the site, open the /admin URL (e.g. http://127.0.0.1:8000/admin ) and enter your new superuser userid and password credentials (you'll be redirected to the login page, and then back to the /admin URL after you've entered your details).


1 Answers

Based on the information you provided you should check this part of Django's documentation:

Adding views to admin sites (note: the link is valid for version 1.5 since version 1.3 is not supported anymore - the solution is still valid).

Then you could check this blog post and this question for some further inspiration and details.


Based on your example I really don't get why you just don't use a regular ModelAdmin with some filtering options:

class QuestionAdmin(admin.ModelAdmin):     list_filter = ('topic',) 
like image 51
arie Avatar answered Nov 04 '22 11:11

arie