-1

I try to register model with the admin site from view.py, so model's admin interface would appear after I go to matching url. But when I go to matching url only model's name without reference appears, models instances doesn't display. It's necessary to register model from 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
from django.shortcuts import redirect
from polls.models import Poll

def index(request):
    admin.site.register(Poll)
    return redirect('/admin')
g0g0
  • 62
  • 7
  • Please, go through part two of the [tutorial](https://docs.djangoproject.com/en/1.5/intro/tutorial02/) – Burhan Khalid Jul 23 '13 at 08:01
  • It's necessary to register model from views. I simplified problem actually I'm trying to create a dynamic models. – g0g0 Jul 23 '13 at 08:30
  • Dynamic models? Models are tied with a database, and they are not dynamic. What are you trying to do anyway? – Burhan Khalid Jul 23 '13 at 08:45
  • something like this [DynamicModels](https://code.djangoproject.com/wiki/DynamicModels) – g0g0 Jul 23 '13 at 08:51
  • See [this answer](http://stackoverflow.com/questions/7933596/django-dynamic-model-fields/7934577#7934577) which is linked from the page you posted. – Burhan Khalid Jul 23 '13 at 08:53
  • I have created dynamic models, I have problem only with admin interface as described in post. – g0g0 Jul 23 '13 at 08:56

1 Answers1

0

solution:

from django.contrib import admin
from polls.models import Poll
from django.http import HttpResponse
from django.shortcuts import redirect
from django.core.urlresolvers import clear_url_caches
from django.utils.importlib import import_module
from django.conf import settings

def index(request):
    admin.site.register(Poll)
    reload(import_module(settings.ROOT_URLCONF))
    clear_url_caches()
    return redirect('/admin')
g0g0
  • 62
  • 7