django tutorial #7 completed
This commit is contained in:
parent
751a1df517
commit
4939405683
|
@ -60,7 +60,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': [
|
||||||
|
|
|
@ -2,10 +2,25 @@ from django.contrib import admin
|
||||||
|
|
||||||
# Register your models here.
|
# Register your models here.
|
||||||
|
|
||||||
from .models import Question
|
from .models import Choice, Question
|
||||||
|
|
||||||
from .models import Choice
|
# stacked: that's lot of space
|
||||||
|
#class ChoiceInline(admin.StackedInline):
|
||||||
|
class ChoiceInline(admin.TabularInline):
|
||||||
|
model = Choice
|
||||||
|
extra = 3
|
||||||
|
|
||||||
admin.site.register(Question)
|
class QuestionAdmin(admin.ModelAdmin):
|
||||||
|
# # this way we changed the order
|
||||||
|
#fields = ['pub_date', 'question_text']
|
||||||
|
# # different organization of fields
|
||||||
|
fieldsets = [
|
||||||
|
(None, {'fields': ['question_text']}),
|
||||||
|
('Date information', {'fields': ['pub_date']}),
|
||||||
|
]
|
||||||
|
inlines = [ChoiceInline]
|
||||||
|
list_display = ('question_text', 'pub_date', 'was_published_recently')
|
||||||
|
list_filter = ['pub_date']
|
||||||
|
search_fields = ['question_text']
|
||||||
|
|
||||||
admin.site.register(Choice)
|
admin.site.register(Question, QuestionAdmin)
|
||||||
|
|
|
@ -15,6 +15,9 @@ class Question(models.Model):
|
||||||
#return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
|
#return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
|
||||||
now = timezone.now()
|
now = timezone.now()
|
||||||
return now - datetime.timedelta(days=1) <= self.pub_date <= now
|
return now - datetime.timedelta(days=1) <= self.pub_date <= 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)
|
||||||
|
|
|
@ -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' %}">Polls
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block nav-global %}{% endblock %}
|
Loading…
Reference in New Issue