Harry
Harry

Reputation: 13329

Django admin App

I am building a app. The app will build a Poll OR a Quiz. So my models will have a type field(Poll, Quiz)

Now i would like to display the 2 "Types" in the admin App list. But i dont what to create two apps Poll and Quiz. Is there a way, to display the 2 options in the list and then when you click on lets say Poll, the type field is set to Poll and then you fill in the rest of the models fields.

Thanks

Upvotes: 1

Views: 662

Answers (2)

Harry
Harry

Reputation: 13329

alas!I figured it out! What you use is a Django Proxy Model http://docs.djangoproject.com/en/1.1/topics/db/models/#id8

So I set up a Proxy model in my models.py file and then in admin.py I just used the proxy models as Admin.

Upvotes: 1

HWM-Rocker
HWM-Rocker

Reputation: 617

have a short look to the second tutorial page of django. It describes the how to do that.

http://docs.djangoproject.com/en/1.1/intro/tutorial02/#intro-tutorial02

  1. You need to activate the admin site:
    1. Add "django.contrib.admin" to your INSTALLED_APPS setting.
    2. Run python manage.py syncdb.
    3. update urls.py

# Uncomment the next two lines to enable the admin:

from django.contrib import admin
admin.autodiscover()

add the next line to urlpatterns

    (r'^admin/', include(admin.site.urls)),

2 . You need to add your models to the admin interface

You only have to create a admin.py in your application directory (e.g. polls) and fill in the following content:

from mysite.polls.models import Poll, Quiz
from django.contrib import admin

admin.site.register(Poll)
admin.site.register(Quiz)

you have to change the first line of course to fit with your project name.

Hope this will help!

Upvotes: 1

Related Questions