Completed Models and starter work

This commit is contained in:
Ceferino Patino 2022-05-17 07:04:52 -05:00
commit e699bb0926
22 changed files with 741 additions and 0 deletions

0
housewars/__init__.py Normal file
View file

6
housewars/admin.py Normal file
View file

@ -0,0 +1,6 @@
from django.contrib import admin
from .models import Activity, Entry
# Register your models here.
admin.site.register(Activity)
admin.site.register(Entry)

6
housewars/apps.py Normal file
View file

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

View file

@ -0,0 +1,36 @@
# Generated by Django 4.0.4 on 2022-05-16 23:29
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Activity',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=100)),
('quota', models.IntegerField()),
('time', models.IntegerField(choices=[(30, '30'), (60, '60')])),
],
),
migrations.CreateModel(
name='Entry',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('first_name', models.CharField(max_length=100)),
('last_name', models.CharField(max_length=100)),
('email', models.EmailField(max_length=100)),
('grade', models.CharField(choices=[('9th', '9Th'), ('10th', '10Th'), ('11th', '11Th'), ('12th', '12Th')], max_length=5)),
('activity1', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='activity1', to='housewars.activity')),
('activity2', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='activity2', to='housewars.activity')),
],
),
]

View file

@ -0,0 +1,17 @@
# Generated by Django 4.0.4 on 2022-05-16 23:37
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('housewars', '0001_initial'),
]
operations = [
migrations.AlterModelTable(
name='activity',
table='Activities',
),
]

View file

@ -0,0 +1,25 @@
# Generated by Django 4.0.4 on 2022-05-16 23:38
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('housewars', '0002_alter_activity_table'),
]
operations = [
migrations.AlterModelOptions(
name='activity',
options={'verbose_name_plural': 'Activities'},
),
migrations.AlterModelOptions(
name='entry',
options={'verbose_name_plural': 'Entries'},
),
migrations.AlterModelTable(
name='activity',
table=None,
),
]

View file

@ -0,0 +1,18 @@
# Generated by Django 4.0.4 on 2022-05-17 02:04
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('housewars', '0003_alter_activity_options_alter_entry_options_and_more'),
]
operations = [
migrations.AlterField(
model_name='entry',
name='grade',
field=models.IntegerField(choices=[(9, '9th/Freshman'), (10, '10th/Sophomore'), (11, '11th/Junior'), (12, '12th/Senior')]),
),
]

View file

52
housewars/models.py Normal file
View file

@ -0,0 +1,52 @@
from django.db import models
from django.forms import ValidationError
# Create your models here.
class Activity(models.Model):
class Meta:
verbose_name_plural = "Activities"
TimeslotChoices = [
(30, '30'),
(60, '60')
]
name = models.CharField(max_length=100)
quota = models.IntegerField()
time = models.IntegerField(choices=TimeslotChoices)
def __str__(self):
return f"{self.name} ({self.time})"
class Entry(models.Model):
class Meta:
verbose_name_plural = "Entries"
GradeChoices = (
(9, '9th/Freshman'),
(10, '10th/Sophomore'),
(11, '11th/Junior'),
(12, '12th/Senior'),
)
first_name = models.CharField(max_length=100)
last_name = models.CharField(max_length=100)
email = models.EmailField(max_length=100)
grade = models.IntegerField(choices=GradeChoices)
activity1 = models.ForeignKey(
Activity, related_name='activity1', on_delete=models.CASCADE)
activity2 = models.ForeignKey(
Activity, related_name='activity2', on_delete=models.CASCADE)
def clean(self):
if self.activity1.time + self.activity2.time > 60:
raise ValidationError(
"Please only pick activities adding up to one hour.")
else:
super().clean()
def __str__(self):
return f"{self.first_name} {self.last_name}"

View file

@ -0,0 +1,42 @@
<html>
<head>
<meta charset="ISO-8859-1" />
<meta name="description" content="A website made by C4 Patino" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link
href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-+0n0xVW2eSR5OomGNYDnhzAbDsOXxcvSN1TPprVMTNDbiYZCxYbOOl7+AMvyTG2x"
crossorigin="anonymous"
/>
{% if title %}
<title>Django Blog - {{title}}</title>
{% else %}
<title>Django Blog</title>
{% endif %}
</head>
<body>
<main role="main" class="container">
<div class="content-section">
<form method="POST">
{% csrf_token %}
<fieldset class="form-group">
<legend class="border-bottom mb-4">Blog Post</legend>
{{ form }}
</fieldset>
<div>
<button class="btn btn-outline-info" type="submit">
Post
</button>
</div>
</form>
</div>
</main>
<script
src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/js/bootstrap.bundle.min.js"
integrity="sha384-gtEjrD/SeCtmISkJkNUaaKMoLD0//ElJ19smozuHV6z3Iehds+3Ulb9Bn9Plx0x4"
crossorigin="anonymous"
></script>
</body>
</html>

3
housewars/tests.py Normal file
View file

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

24
housewars/urls.py Normal file
View file

@ -0,0 +1,24 @@
"""CollegiateHouseWars URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/4.0/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path, include
from . import views
app_name = 'housewars'
urlpatterns = [
path('', views.EntryCreateView.as_view(), name='entry_create'),
]

10
housewars/views.py Normal file
View file

@ -0,0 +1,10 @@
from django.shortcuts import render
from django.views.generic import CreateView
from .models import Entry
class EntryCreateView(CreateView):
model = Entry
fields = ['first_name', 'last_name', 'email',
'grade', 'activity1', 'activity2']