Compare commits

..

3 Commits

Author SHA1 Message Date
174c101fb1
Such temperature 2024-11-30 19:53:05 -05:00
4e7e47dd94
Doing a cc4e 2024-11-30 15:53:33 -05:00
a5ce30aeeb
Up through tutorial part 3, the first bit 2024-09-16 06:56:04 -04:00
10 changed files with 110 additions and 17 deletions

19
cc4e/fc.c Normal file
View File

@ -0,0 +1,19 @@
#include <stdio.h>
/* print Fahrenheit-Celsius table
for f = 0, 20, ..., 300 */
int main() {
int lower, upper, step;
float fahr, celsius;
lower = 0; /* lower limit of temperature table */
upper = 300; /* upper limit */
step = 20; /* step size */
fahr = lower;
while (fahr <= upper) {
celsius = (5.0/9.0) * (fahr-32.0);
printf("%4.0f %6.1f\n", fahr, celsius);
fahr = fahr + step;
}
}

12
cc4e/fc_2.c Normal file
View File

@ -0,0 +1,12 @@
#include <stdio.h>
#define LOWER 0 /* lower limit of table */
#define UPPER 300 /* upper limit */
#define STEP 20 /* step size */
int main() { /* Fahrenheit-Celsius table */
int fahr;
for (fahr = LOWER; fahr <= UPPER; fahr = fahr + STEP)
printf("%4d %6.1f\n", fahr, (5.0/9.0)*(fahr-32));
}

5
cc4e/hello.c Normal file
View File

@ -0,0 +1,5 @@
#include <stdio.h>
int main() {
printf("hello, world\n");
return 0;
}

View File

@ -1,3 +1,5 @@
from django.contrib import admin from django.contrib import admin
# Register your models here. from .models import Question
admin.site.register(Question)

View File

@ -2,5 +2,5 @@ from django.apps import AppConfig
class PollsConfig(AppConfig): class PollsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField' default_auto_field = "django.db.models.BigAutoField"
name = 'polls' name = "polls"

View File

@ -5,28 +5,47 @@ from django.db import migrations, models
class Migration(migrations.Migration): class Migration(migrations.Migration):
initial = True initial = True
dependencies = [ dependencies = []
]
operations = [ operations = [
migrations.CreateModel( migrations.CreateModel(
name='Question', name="Question",
fields=[ fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), (
('question_text', models.CharField(max_length=200)), "id",
('pub_date', models.DateTimeField(verbose_name='date published')), 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( migrations.CreateModel(
name='Choice', name="Choice",
fields=[ fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), (
('choice_text', models.CharField(max_length=200)), "id",
('votes', models.IntegerField(default=0)), models.BigAutoField(
('question', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='polls.question')), 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"
),
),
], ],
), ),
] ]

View File

@ -1,12 +1,24 @@
import datetime
from django.db import models from django.db import models
from django.utils import timezone
class Question(models.Model): class Question(models.Model):
question_text = models.CharField(max_length=200) question_text = models.CharField(max_length=200)
pub_date = models.DateTimeField("date published") 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): class Choice(models.Model):
question = models.ForeignKey(Question, on_delete=models.CASCADE) question = models.ForeignKey(Question, on_delete=models.CASCADE)
choice_text = models.CharField(max_length=200) choice_text = models.CharField(max_length=200)
votes = models.IntegerField(default=0) votes = models.IntegerField(default=0)
def __str__(self):
return self.choice_text

View File

@ -5,4 +5,7 @@ from . import views
urlpatterns = [ urlpatterns = [
path("", views.index, name="index"), path("", views.index, name="index"),
path("<int:question_id>/", views.detail, name="detail"),
path("<int:question_id>/results/", views.results, name="results"),
path("<int:question_id>/vote/", views.vote, name="vote"),
] ]

View File

@ -1,6 +1,26 @@
from django.http import HttpResponse from django.http import HttpResponse
from .models import Question
def index(request):
def index(request) -> HttpResponse:
latest_question_list = Question.objects.order_by("-pub_date")[:5]
output = ", ".join([q.question_text for q in latest_question_list])
return HttpResponse(output.encode())
def detail(request, question_id) -> HttpResponse:
_ = request _ = request
return HttpResponse(b"Hello, world. You're at the polls index.") return HttpResponse(f"You're looking at question {question_id}.".encode())
def results(request, question_id) -> HttpResponse:
_ = request
return HttpResponse(
f"You're looking at the results of question {question_id}".encode()
)
def vote(request, question_id) -> HttpResponse:
_ = request
return HttpResponse(f"You're voting on question {question_id}".encode())

View File

@ -1,2 +1,3 @@
Django Django
django-stubs
ruff ruff