django call admin.site.register from view -


i try register model admin site view.py, model's admin interface appear after go matching url. when go matching url model's name without reference appears, models instances doesn't display. it's necessary register model views.

models.py

from django.db import models  class poll(models.model):     question = models.charfield(max_length=200)     pub_date = models.datetimefield('date published') 

views.py

from django.contrib import admin django.shortcuts import redirect polls.models import poll  def index(request):     admin.site.register(poll)     return redirect('/admin') 

solution:

from django.contrib import admin polls.models import poll django.http import httpresponse django.shortcuts import redirect django.core.urlresolvers import clear_url_caches django.utils.importlib import import_module django.conf import settings  def index(request):     admin.site.register(poll)     reload(import_module(settings.root_urlconf))     clear_url_caches()     return redirect('/admin') 

Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -