Compare commits
No commits in common. "2b54e70f1b3fc2bdcdda43ed1d7b9be57e0b2c4e" and "f565f2437be7550c3dcd6e827982839c7b76da00" have entirely different histories.
2b54e70f1b
...
f565f2437b
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,5 +1,3 @@
|
|||||||
env/
|
env/
|
||||||
.vscode
|
.vscode
|
||||||
__pycache__
|
__pycache__
|
||||||
db.sqlite3
|
|
||||||
.env
|
|
Binary file not shown.
@ -1,5 +1,3 @@
|
|||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
|
||||||
from .models import Question
|
# Register your models here.
|
||||||
|
|
||||||
admin.site.register(Question)
|
|
||||||
|
@ -1,52 +0,0 @@
|
|||||||
# Generated by Django 4.1 on 2022-09-09 02:24
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
import django.db.models.deletion
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
initial = True
|
|
||||||
|
|
||||||
dependencies = []
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.CreateModel(
|
|
||||||
name="Question",
|
|
||||||
fields=[
|
|
||||||
(
|
|
||||||
"id",
|
|
||||||
models.BigAutoField(
|
|
||||||
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.CreateModel(
|
|
||||||
name="Choice",
|
|
||||||
fields=[
|
|
||||||
(
|
|
||||||
"id",
|
|
||||||
models.BigAutoField(
|
|
||||||
auto_created=True,
|
|
||||||
primary_key=True,
|
|
||||||
serialize=False,
|
|
||||||
verbose_name="ID",
|
|
||||||
),
|
|
||||||
),
|
|
||||||
("choice_text", models.CharField(max_length=200)),
|
|
||||||
("votes", models.IntegerField(default=0)),
|
|
||||||
(
|
|
||||||
"question",
|
|
||||||
models.ForeignKey(
|
|
||||||
on_delete=django.db.models.deletion.CASCADE, to="polls.question"
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
]
|
|
@ -1,22 +1,3 @@
|
|||||||
import datetime
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.utils import timezone
|
|
||||||
|
|
||||||
class Question(models.Model):
|
# Create your models here.
|
||||||
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() - datetime.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
|
|
||||||
|
@ -4,12 +4,4 @@ from . import views
|
|||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('', views.index, name='index'),
|
path('', views.index, name='index'),
|
||||||
# ex: /polls/
|
|
||||||
path('', views.index, name='index'),
|
|
||||||
# ex: /polls/5/
|
|
||||||
path('<int:question_id>/', views.detail, name='detail'),
|
|
||||||
# ex: /polls/5/results/
|
|
||||||
path('<int:question_id>/results/', views.results, name='results'),
|
|
||||||
# ex: /polls/5/vote/
|
|
||||||
path('<int:question_id>/vote/', views.vote, name='vote'),
|
|
||||||
]
|
]
|
@ -5,14 +5,4 @@ from django.http import HttpResponse
|
|||||||
|
|
||||||
|
|
||||||
def index(request):
|
def index(request):
|
||||||
return HttpResponse("Hello, world. You're at the polls index.")
|
return HttpResponse("Hello, world. You're at the polls index.")
|
||||||
|
|
||||||
def detail(request, question_id):
|
|
||||||
return HttpResponse("You're looking at question %s." % question_id)
|
|
||||||
|
|
||||||
def results(request, question_id):
|
|
||||||
response = "You're looking at the results of question %s."
|
|
||||||
return HttpResponse(response % question_id)
|
|
||||||
|
|
||||||
def vote(request, question_id):
|
|
||||||
return HttpResponse("You're voting on question %s." % question_id)
|
|
Loading…
x
Reference in New Issue
Block a user