django: starting the django tutorial
This commit is contained in:
0
django/mysite/polls/__init__.py
Normal file
0
django/mysite/polls/__init__.py
Normal file
5
django/mysite/polls/admin.py
Normal file
5
django/mysite/polls/admin.py
Normal file
@@ -0,0 +1,5 @@
|
||||
from django.contrib import admin
|
||||
from .models import Question, Choice
|
||||
|
||||
admin.site.register(Question)
|
||||
admin.site.register(Choice)
|
||||
5
django/mysite/polls/apps.py
Normal file
5
django/mysite/polls/apps.py
Normal file
@@ -0,0 +1,5 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class PollsConfig(AppConfig):
|
||||
name = 'polls'
|
||||
36
django/mysite/polls/migrations/0001_initial.py
Normal file
36
django/mysite/polls/migrations/0001_initial.py
Normal file
@@ -0,0 +1,36 @@
|
||||
# Generated by Django 2.0.5 on 2018-05-06 18:51
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Choice',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('choice_text', models.CharField(max_length=200)),
|
||||
('votes', models.IntegerField(default=0)),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Question',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('question_text', models.CharField(max_length=200)),
|
||||
('pub_date', models.DateTimeField(verbose_name='date published')),
|
||||
],
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='choice',
|
||||
name='question',
|
||||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='polls.Question'),
|
||||
),
|
||||
]
|
||||
0
django/mysite/polls/migrations/__init__.py
Normal file
0
django/mysite/polls/migrations/__init__.py
Normal file
20
django/mysite/polls/models.py
Normal file
20
django/mysite/polls/models.py
Normal file
@@ -0,0 +1,20 @@
|
||||
from django.db import models
|
||||
from django.utils import timezone
|
||||
|
||||
class Question(models.Model):
|
||||
question_text = models.CharField(max_length=200)
|
||||
pub_date = models.DateTimeField('date published')
|
||||
|
||||
def __str__(self):
|
||||
return self.question_text
|
||||
|
||||
def was_published_recently(self):
|
||||
return self.pub_date >= timezone.now() - timezone.timedelta(days=1)
|
||||
|
||||
class Choice(models.Model):
|
||||
question = models.ForeignKey(Question, on_delete=models.CASCADE)
|
||||
choice_text = models.CharField(max_length=200)
|
||||
votes = models.IntegerField(default=0)
|
||||
|
||||
def __str__(self):
|
||||
return self.choice_text
|
||||
3
django/mysite/polls/tests.py
Normal file
3
django/mysite/polls/tests.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
7
django/mysite/polls/urls.py
Normal file
7
django/mysite/polls/urls.py
Normal file
@@ -0,0 +1,7 @@
|
||||
from django.urls import path
|
||||
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
path('', views.index, name='index'),
|
||||
]
|
||||
6
django/mysite/polls/views.py
Normal file
6
django/mysite/polls/views.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from django.shortcuts import render
|
||||
from django.http import HttpResponse
|
||||
|
||||
# Create your views here.
|
||||
def index(request):
|
||||
return HttpResponse("Hello, world. You're at the polls index.")
|
||||
Reference in New Issue
Block a user