Reputation: 13
I am new to Django and have been going through the official tutorial on www.djangoproject.com. I have successfully implemented the tutorial 1 in my system but I am unable to figure out why the "plus" or "add" button is not showing up in the admin panel.
I am using django 1.6.1 It is a pretty simple code but I am unable to figure it out since I don't have any prior knowledge of Django. Help will be appreciated.
Below is the code for the files models.py and admin.py
models.py
from django.db import models
class Poll(models.Model):
question = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
def __unicode__(self): # Python 3: def __str__(self):
return self.question
class Choice(models.Model):
poll = models.ForeignKey(Poll)
choice_text = models.CharField(max_length=200)
votes = models.IntegerField(default=0)
def __unicode__(self): # Python 3: def __str__(self):
return self.choice_text
admin.py
from django.contrib import admin
from polls.models import Choice, Poll
"""class ChoiceInline(admin.TabularInline):
model = Choice
class PollAdmin(admin.ModelAdmin):
fieldsets = [
(None, {'fields': ['question']}),
('Date information', {'fields': ['pub_date'], 'classes': ['collapse']}),
]
list_display = ('question', 'pub_date')
inlines = [ChoiceInline]
list_filter = ['pub_date']
search_fields = ['question']
"""
admin.site.register(Choice)
Upvotes: 1
Views: 478
Reputation: 473893
First of all, it is unclear why are the classes in the admin.py
written inside the string in triple quotes.
Assuming this is a typo/intentional, you still need to register()
the PollAdmin
:
admin.site.register(Poll, PollAdmin)
The complete code at this step should look like:
from django.contrib import admin
from polls.models import Choice, Poll
class PollAdmin(admin.ModelAdmin):
fieldsets = [
(None, {'fields': ['question']}),
('Date information', {'fields': ['pub_date'], 'classes': ['collapse']}),
]
admin.site.register(Choice)
admin.site.register(Poll, PollAdmin)
Upvotes: 1