dm 4 meses atrás
pai
commit
49f5af1ff3

+ 3 - 0
.gitignore

@@ -0,0 +1,3 @@
+/env
+__pycache__/
+

BIN
db.sqlite3


+ 1 - 0
mysite/settings.py

@@ -31,6 +31,7 @@ ALLOWED_HOSTS = []
 # Application definition
 
 INSTALLED_APPS = [
+    'polls.apps.PollsConfig',
     'django.contrib.admin',
     'django.contrib.auth',
     'django.contrib.contenttypes',

+ 2 - 1
mysite/urls.py

@@ -15,8 +15,9 @@ Including another URLconf
     2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
 """
 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),
 ]

+ 0 - 0
polls/__init__.py


+ 3 - 0
polls/admin.py

@@ -0,0 +1,3 @@
+from django.contrib import admin
+
+# Register your models here.

+ 6 - 0
polls/apps.py

@@ -0,0 +1,6 @@
+from django.apps import AppConfig
+
+
+class PollsConfig(AppConfig):
+    default_auto_field = 'django.db.models.BigAutoField'
+    name = 'polls'

+ 32 - 0
polls/migrations/0001_initial.py

@@ -0,0 +1,32 @@
+# Generated by Django 5.1.4 on 2024-12-22 11:12
+
+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='Choise',
+            fields=[
+                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+                ('chouise_text', models.CharField(max_length=200)),
+                ('votes', models.IntegerField(default=0)),
+                ('question', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='polls.question')),
+            ],
+        ),
+    ]

+ 0 - 0
polls/migrations/__init__.py


+ 13 - 0
polls/models.py

@@ -0,0 +1,13 @@
+from django.db import models
+
+# Create your models here.
+
+class Question(models.Model):
+    question_text = models.CharField(max_length=200)
+    pub_date = models.DateTimeField("date published")
+
+
+class Choise(models.Model):
+    question = models.ForeignKey(Question, on_delete=models.CASCADE)
+    chouise_text = models.CharField(max_length=200)
+    votes = models.IntegerField(default=0)

+ 3 - 0
polls/tests.py

@@ -0,0 +1,3 @@
+from django.test import TestCase
+
+# Create your tests here.

+ 6 - 0
polls/urls.py

@@ -0,0 +1,6 @@
+from django.urls import path
+from . import views
+
+urlpatterns = [
+    path("", views.index, name='index'),
+]

+ 7 - 0
polls/views.py

@@ -0,0 +1,7 @@
+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.")