这段代码来自djangoproject.com教程。有人能解释一下为什么这句话是这样写的吗:

inlines =[ChoiceInline]

而不是
inlines = ChoiceInline

为什么类ChoiceInline周围有方括号?
from django.contrib import admin
from naslovnica.models import Poll
from naslovnica.models import Choice

class ChoiceInline(admin.TabularInline):
    model = Choice
    extra = 3

class PollAdmin(admin.ModelAdmin):
    fieldsets = [
    (None,               {'fields': ['question']}),
    ('Date information', {'fields': ['pub_date'], 'classes': ['collapse']}),
    ]
    inlines =[ChoiceInline]
    list_display = ('question', 'pub_date', 'was_published_recently')
    search_fields = ['question']
    list_filter = ['pub_date']

admin.site.register(Poll, PollAdmin)

最佳答案

inlines =[ChoiceInline]这不是对类的调用。这将创建第一个元素为class的新列表。
类调用将作为ChoiceInline()执行。

10-05 23:04