django: finish tutorial
This commit is contained in:
parent
bc6a424fbe
commit
f342fc91db
|
@ -55,7 +55,7 @@ ROOT_URLCONF = 'mysite.urls'
|
||||||
TEMPLATES = [
|
TEMPLATES = [
|
||||||
{
|
{
|
||||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||||
'DIRS': [],
|
'DIRS': [os.path.join(BASE_DIR, 'templates')],
|
||||||
'APP_DIRS': True,
|
'APP_DIRS': True,
|
||||||
'OPTIONS': {
|
'OPTIONS': {
|
||||||
'context_processors': [
|
'context_processors': [
|
||||||
|
|
|
@ -1,5 +1,21 @@
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from .models import Question, Choice
|
from .models import Question, Choice
|
||||||
|
|
||||||
admin.site.register(Question)
|
|
||||||
admin.site.register(Choice)
|
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)
|
||||||
|
|
|
@ -13,6 +13,10 @@ class Question(models.Model):
|
||||||
def was_published_recently(self):
|
def was_published_recently(self):
|
||||||
return timezone.now() - recent <= self.pub_date <= timezone.now()
|
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):
|
class Choice(models.Model):
|
||||||
question = models.ForeignKey(Question, on_delete=models.CASCADE)
|
question = models.ForeignKey(Question, on_delete=models.CASCADE)
|
||||||
choice_text = models.CharField(max_length=200)
|
choice_text = models.CharField(max_length=200)
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
{% extends "admin/base.html" %}
|
||||||
|
|
||||||
|
{% block title %}{{ title }} | {{ site_title|default:_('Django site admin') }}{% endblock %}
|
||||||
|
|
||||||
|
{% block branding %}
|
||||||
|
<h1 id="site-name"><a href="{% url 'admin:index' %}">Ministry of Polls</a></h1>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block nav-global %}{% endblock %}
|
Loading…
Reference in New Issue