파이썬

admin.py 고치기

mcdn 2020. 9. 20. 17:24
반응형
from django.contrib import admin
from polls.models import Question, Choice

# Register your models here.
class ChoiceInline(admin.TabularInline):#StackedInline
    model = Choice
    extra = 2

class QuestionAdmin(admin.ModelAdmin):
    fieldsets = [
        ('Question Statement', {'fields':['question_text']}),
        ('Date Information', {'fields': ['pub_date'], 'classes':['collapse']}),
    ]
    inlines = [ChoiceInline] # choice 모델 클래스 같이 보기
    list_display = ('question_text', 'pub_date')# pubdate 추가됨
    list_filter = ['pub_date'] # 필드 사이드바 today any time 등 
    search_fields = ['question_text'] # 검색박스 like query
    #fields = ['pub_date', 'question_text'] #fieldset 이전 field나열 

admin.site.register(Question, QuestionAdmin)
admin.site.register(Choice)

반응형