diff --git a/djoy/.gitignore b/djoy/.gitignore index 21d0b89..ef29d7f 100644 --- a/djoy/.gitignore +++ b/djoy/.gitignore @@ -1 +1,2 @@ .venv/ +*.sqlite3 diff --git a/djoy/djoy/settings.py b/djoy/djoy/settings.py index 1cf2f67..3be5e82 100644 --- a/djoy/djoy/settings.py +++ b/djoy/djoy/settings.py @@ -10,17 +10,18 @@ For the full list of settings and their values, see https://docs.djangoproject.com/en/5.1/ref/settings/ """ -from pathlib import Path +import os +import pathlib # Build paths inside the project like this: BASE_DIR / 'subdir'. -BASE_DIR = Path(__file__).resolve().parent.parent +BASE_DIR = pathlib.Path(__file__).resolve().parent.parent # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/5.1/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = "django-insecure-^0yh(u^q7wf!+8kc-gr2ccu7_$gtg_y#!d3zs0hvm7we4x!4@x" +SECRET_KEY = os.environ.get("DJOY_SECRET_KEY", "django-insecure-0xohno") # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True @@ -31,6 +32,7 @@ ALLOWED_HOSTS = [] # Application definition INSTALLED_APPS = [ + "polls.apps.PollsConfig", "django.contrib.admin", "django.contrib.auth", "django.contrib.contenttypes", diff --git a/djoy/djoy/urls.py b/djoy/djoy/urls.py index 020990b..bc4edc2 100644 --- a/djoy/djoy/urls.py +++ b/djoy/djoy/urls.py @@ -16,8 +16,9 @@ Including another URLconf """ from django.contrib import admin -from django.urls import path +from django.urls import include, path urlpatterns = [ + path("polls/", include("polls.urls")), path("admin/", admin.site.urls), ] diff --git a/djoy/polls/__init__.py b/djoy/polls/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/djoy/polls/admin.py b/djoy/polls/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/djoy/polls/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/djoy/polls/apps.py b/djoy/polls/apps.py new file mode 100644 index 0000000..5a5f94c --- /dev/null +++ b/djoy/polls/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class PollsConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'polls' diff --git a/djoy/polls/migrations/0001_initial.py b/djoy/polls/migrations/0001_initial.py new file mode 100644 index 0000000..63290b2 --- /dev/null +++ b/djoy/polls/migrations/0001_initial.py @@ -0,0 +1,32 @@ +# Generated by Django 5.1.1 on 2024-09-16 01:23 + +import django.db.models.deletion +from django.db import migrations, models + + +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')), + ], + ), + ] diff --git a/djoy/polls/migrations/__init__.py b/djoy/polls/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/djoy/polls/models.py b/djoy/polls/models.py new file mode 100644 index 0000000..380716f --- /dev/null +++ b/djoy/polls/models.py @@ -0,0 +1,12 @@ +from django.db import models + + +class Question(models.Model): + question_text = models.CharField(max_length=200) + pub_date = models.DateTimeField("date published") + + +class Choice(models.Model): + question = models.ForeignKey(Question, on_delete=models.CASCADE) + choice_text = models.CharField(max_length=200) + votes = models.IntegerField(default=0) diff --git a/djoy/polls/tests.py b/djoy/polls/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/djoy/polls/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/djoy/polls/urls.py b/djoy/polls/urls.py new file mode 100644 index 0000000..0a44982 --- /dev/null +++ b/djoy/polls/urls.py @@ -0,0 +1,8 @@ +from django.urls import path + +from . import views + + +urlpatterns = [ + path("", views.index, name="index"), +] diff --git a/djoy/polls/views.py b/djoy/polls/views.py new file mode 100644 index 0000000..b47b38f --- /dev/null +++ b/djoy/polls/views.py @@ -0,0 +1,6 @@ +from django.http import HttpResponse + + +def index(request): + _ = request + return HttpResponse(b"Hello, world. You're at the polls index.")