Django教程02中未显示添加按钮 [英] Add button not showing up in Django tutorial 02

查看:102
本文介绍了Django教程02中未显示添加按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Django的新手,并且已经通过了www.djangoproject.com上的官方教程。我已经在系统中成功实现了教程1,但是我无法弄清为什么在管理面板中没有显示加号或添加按钮

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.

我正在使用 django 1.6.1
这是一个非常简单的代码,但是由于我没有任何先验知识,因此无法弄清楚Django的。会得到帮助。

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.

下面是文件models.py和admin.py的代码

Below is the code for the files models.py and admin.py

models .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)


推荐答案

首先,目前尚不清楚为什么 admin.py 中的类写成三重字符串

First of all, it is unclear why are the classes in the admin.py written inside the string in triple quotes.

假设这是拼写错误/故意输入,您仍然需要 register() PollAdmin

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)

这篇关于Django教程02中未显示添加按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆