diff --git a/django/mysite/mysite/settings.py b/django/mysite/mysite/settings.py index a84bb26..02b78e5 100644 --- a/django/mysite/mysite/settings.py +++ b/django/mysite/mysite/settings.py @@ -55,7 +55,7 @@ ROOT_URLCONF = 'mysite.urls' TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'DIRS': [], + 'DIRS': [os.path.join(BASE_DIR, 'templates')], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ diff --git a/django/mysite/polls/admin.py b/django/mysite/polls/admin.py index 17a55fa..e537139 100644 --- a/django/mysite/polls/admin.py +++ b/django/mysite/polls/admin.py @@ -1,5 +1,21 @@ from django.contrib import admin from .models import Question, Choice -admin.site.register(Question) -admin.site.register(Choice) \ No newline at end of file + +class ChoiceInline(admin.TabularInline): + model = Choice + extra = 3 + +class QuestionAdmin(admin.ModelAdmin): + # fields = ['pub_date', 'question_text'] + fieldsets = [ + (None, {'fields': ['question_text']}), + ('Date information', {'fields': ['pub_date'], + 'classes': ['collapse']}), + ] + inlines = [ChoiceInline] + list_display = ('question_text', 'pub_date', 'was_published_recently') + list_filter = ['pub_date'] + search_fields = ['question_text'] + +admin.site.register(Question, QuestionAdmin) diff --git a/django/mysite/polls/models.py b/django/mysite/polls/models.py index f819cde..1e858d2 100644 --- a/django/mysite/polls/models.py +++ b/django/mysite/polls/models.py @@ -13,6 +13,10 @@ class Question(models.Model): def was_published_recently(self): return timezone.now() - recent <= self.pub_date <= timezone.now() + was_published_recently.admin_order_field = 'pub_date' + was_published_recently.boolean = True + was_published_recently.short_description = 'Published recently?' + class Choice(models.Model): question = models.ForeignKey(Question, on_delete=models.CASCADE) choice_text = models.CharField(max_length=200) diff --git a/django/mysite/templates/admin/base_site.html b/django/mysite/templates/admin/base_site.html new file mode 100644 index 0000000..fedd7ad --- /dev/null +++ b/django/mysite/templates/admin/base_site.html @@ -0,0 +1,9 @@ +{% extends "admin/base.html" %} + +{% block title %}{{ title }} | {{ site_title|default:_('Django site admin') }}{% endblock %} + +{% block branding %} +