views:

46

answers:

2
+1  Q: 

Django admin App

Hi

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

+1  A: 

Hi,

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!

HWM-Rocker
That is correct but not what i meant. What i meant was this:I have only one models on my models.py. Now in my admin page i would like to give two options under that app. The two options are not actual models. they are just two possible options in a list of one of the fields in the model. so there is a field in my model called question_type = models.CharField(choises=QUESTION_CHOICE)I would like this 2 type of questions in the QUESTION_CHOICE tupil to be displayed in the admin under the App. So if you click on lets say option 1, then that is what the selected option in the list will be
Harry
A: 

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.

Harry