mirror of
https://github.com/Sosokker/ku-polls.git
synced 2025-12-20 05:54:04 +01:00
Customize Admin Page view
This commit is contained in:
parent
d271325ab1
commit
48670592e4
@ -55,15 +55,15 @@ ROOT_URLCONF = 'mysite.urls'
|
||||
|
||||
TEMPLATES = [
|
||||
{
|
||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||
'DIRS': [],
|
||||
'APP_DIRS': True,
|
||||
'OPTIONS': {
|
||||
'context_processors': [
|
||||
'django.template.context_processors.debug',
|
||||
'django.template.context_processors.request',
|
||||
'django.contrib.auth.context_processors.auth',
|
||||
'django.contrib.messages.context_processors.messages',
|
||||
"BACKEND": "django.template.backends.django.DjangoTemplates",
|
||||
"DIRS": [BASE_DIR / "templates"],
|
||||
"APP_DIRS": True,
|
||||
"OPTIONS": {
|
||||
"context_processors": [
|
||||
"django.template.context_processors.debug",
|
||||
"django.template.context_processors.request",
|
||||
"django.contrib.auth.context_processors.auth",
|
||||
"django.contrib.messages.context_processors.messages",
|
||||
],
|
||||
},
|
||||
},
|
||||
|
||||
@ -1,5 +1,22 @@
|
||||
from django.contrib import admin
|
||||
|
||||
from .models import Question
|
||||
from .models import Choice, Question
|
||||
|
||||
admin.site.register(Question)
|
||||
|
||||
class ChoiceInline(admin.TabularInline):
|
||||
model = Choice
|
||||
extra = 3
|
||||
|
||||
|
||||
class QuestionAdmin(admin.ModelAdmin):
|
||||
fieldsets = [
|
||||
(None, {"fields": ["question_text"]}),
|
||||
("Date information", {"fields": ["pub_date"], "classes": ["collapse"]}),
|
||||
]
|
||||
list_display = ["question_text", "pub_date", "was_published_recently"]
|
||||
inlines = [ChoiceInline]
|
||||
list_filter = ["pub_date"]
|
||||
search_fields = ["question_text"]
|
||||
|
||||
|
||||
admin.site.register(Question, QuestionAdmin)
|
||||
@ -2,12 +2,22 @@ import datetime
|
||||
|
||||
from django.db import models
|
||||
from django.utils import timezone
|
||||
from django.contrib import admin
|
||||
|
||||
|
||||
class Question(models.Model):
|
||||
question_text = models.CharField(max_length=200)
|
||||
pub_date = models.DateTimeField("date published")
|
||||
|
||||
def was_published_recently(self):
|
||||
now = timezone.now()
|
||||
return now - datetime.timedelta(days=1) <= self.pub_date <= now
|
||||
|
||||
@admin.display(
|
||||
boolean=True,
|
||||
ordering="pub_date",
|
||||
description="Published recently?",
|
||||
)
|
||||
def was_published_recently(self):
|
||||
now = timezone.now()
|
||||
return now - datetime.timedelta(days=1) <= self.pub_date <= now
|
||||
|
||||
12
polls/templates/admin/base_site.html
Normal file
12
polls/templates/admin/base_site.html
Normal file
@ -0,0 +1,12 @@
|
||||
{% extends "admin/base.html" %}
|
||||
|
||||
{% block title %}{% if subtitle %}{{ subtitle }} | {% endif %}{{ title }} | {{ site_title|default:_('Django site admin') }}{% endblock %}
|
||||
|
||||
{% block branding %}
|
||||
<div id="site-name"><a href="{% url 'admin:index' %}">Polls Administration Page</a></div>
|
||||
{% if user.is_anonymous %}
|
||||
{% include "admin/color_theme_toggle.html" %}
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
{% block nav-global %}{% endblock %}
|
||||
Loading…
Reference in New Issue
Block a user