Commit 6ed2e0c2 authored by Paul Angelo Sy's avatar Paul Angelo Sy

Added Course model and changed views

parent 4009b2fb
from django.contrib import admin from django.contrib import admin
# Register your models here. # Register your models here.
from .models import Assignment from .models import Assignment, Course
admin.site.register(Assignment) admin.site.register(Assignment)
admin.site.register(Course)
# Generated by Django 3.2.12 on 2022-03-31 17:48
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('assignments', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='Course',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('course_code', models.CharField(max_length=10)),
('course_title', models.CharField(max_length=100)),
('section', models.CharField(max_length=3)),
],
),
migrations.AddField(
model_name='assignment',
name='passing_score',
field=models.IntegerField(default=0),
),
migrations.AddField(
model_name='assignment',
name='course',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='assignments', to='assignments.course'),
),
]
# Generated by Django 3.2.12 on 2022-03-31 18:00
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('assignments', '0002_auto_20220401_0148'),
]
operations = [
migrations.AlterField(
model_name='assignment',
name='passing_score',
field=models.IntegerField(default=0, null=True),
),
]
# Generated by Django 3.2.12 on 2022-03-31 18:02
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('assignments', '0003_alter_assignment_passing_score'),
]
operations = [
migrations.RemoveField(
model_name='assignment',
name='course',
),
migrations.RemoveField(
model_name='assignment',
name='passing_score',
),
migrations.DeleteModel(
name='Course',
),
]
# Generated by Django 3.2.12 on 2022-03-31 18:04
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('assignments', '0004_auto_20220401_0202'),
]
operations = [
migrations.AddField(
model_name='assignment',
name='passing_score',
field=models.IntegerField(default=0),
),
]
# Generated by Django 3.2.12 on 2022-03-31 18:07
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('assignments', '0005_assignment_passing_score'),
]
operations = [
migrations.AlterField(
model_name='assignment',
name='passing_score',
field=models.IntegerField(default=0, null=True),
),
]
# Generated by Django 3.2.12 on 2022-03-31 18:13
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('assignments', '0006_alter_assignment_passing_score'),
]
operations = [
migrations.CreateModel(
name='Course',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('course_code', models.CharField(max_length=10)),
('course_title', models.CharField(max_length=100)),
('section', models.CharField(max_length=3)),
],
),
migrations.AddField(
model_name='assignment',
name='course_code',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='assignments.course'),
),
]
# Generated by Django 3.2.12 on 2022-03-31 18:17
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('assignments', '0007_auto_20220401_0213'),
]
operations = [
migrations.AlterField(
model_name='assignment',
name='course_code',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='assignments.course'),
),
]
# Generated by Django 3.2.12 on 2022-03-31 18:29
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('assignments', '0008_alter_assignment_course_code'),
]
operations = [
migrations.AlterField(
model_name='assignment',
name='passing_score',
field=models.IntegerField(default=0, editable=False),
),
]
# Generated by Django 3.2.12 on 2022-04-01 03:13
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('assignments', '0009_alter_assignment_passing_score'),
]
operations = [
migrations.AlterField(
model_name='assignment',
name='passing_score',
field=models.IntegerField(),
),
]
# Generated by Django 3.2.12 on 2022-04-01 03:15
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('assignments', '0010_alter_assignment_passing_score'),
]
operations = [
migrations.AlterField(
model_name='assignment',
name='passing_score',
field=models.IntegerField(editable=False),
),
]
# Generated by Django 3.2.12 on 2022-04-01 03:16
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('assignments', '0011_alter_assignment_passing_score'),
]
operations = [
migrations.AlterField(
model_name='assignment',
name='passing_score',
field=models.IntegerField(editable=False, null=True),
),
]
# Generated by Django 3.2.12 on 2022-04-01 04:17
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('assignments', '0012_alter_assignment_passing_score'),
]
operations = [
migrations.AlterField(
model_name='assignment',
name='passing_score',
field=models.FloatField(null=True),
),
]
# Generated by Django 3.2.12 on 2022-04-01 09:10
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('assignments', '0013_alter_assignment_passing_score'),
]
operations = [
migrations.RemoveField(
model_name='assignment',
name='passing_score',
),
]
# Generated by Django 3.2.12 on 2022-04-01 09:48
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('assignments', '0014_remove_assignment_passing_score'),
]
operations = [
migrations.RemoveField(
model_name='assignment',
name='max_points',
),
]
# Generated by Django 3.2.12 on 2022-04-01 09:48
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('assignments', '0015_remove_assignment_max_points'),
]
operations = [
migrations.AddField(
model_name='assignment',
name='max_points',
field=models.IntegerField(default=0),
),
]
from django.db import models from django.db import models
# Create your models here. # Create your models here.
class Course(models.Model):
course_code = models.CharField(max_length = 10)
course_title = models.CharField(max_length = 100)
section = models.CharField(max_length = 3)
def __str__(self):
return str(self.course_code)
class Assignment(models.Model): class Assignment(models.Model):
name = models.CharField(max_length = 50) name = models.CharField(max_length = 50)
description = models.CharField(max_length = 500) description = models.CharField(max_length = 500)
max_points = models.IntegerField(default=0) max_points = models.IntegerField(default=0)
course_code = models.ForeignKey(Course, on_delete=models.CASCADE, null = True, blank = True)
@property
def get_passing(self):
return int(self.max_points * 0.6)
def __str__(self): def __str__(self):
return self.name return str(self.name)
from django.http import HttpResponse from django.http import HttpResponse
from assignments.models import Assignment, Course
# Create your views here. # Create your views here.
def index(request): def index(request):
return HttpResponse("This is the Assignments page!")
assignmentCount = Assignment.objects.all().count()
assignmentOutput = "Assignments: <br/><br/>"
n = assignmentCount
for n in Assignment.objects.all():
assignmentOutput += ("Assignment Name: " + str(n.name) + "<br/>")
assignmentOutput += ("Description: " + n.description + "<br/>")
assignmentOutput += ("Perfect Score: " + str(n.max_points) + "<br/>")
assignmentOutput += ("Passing Score: " + str(n.get_passing) + "<br/>")
assignmentOutput += ("Course/Section: " + Course.objects.get(course_code = n.course_code).course_code + " ")
assignmentOutput += (Course.objects.get(course_code = n.course_code).course_title + " ")
assignmentOutput += (Course.objects.get(course_code = n.course_code).section + "<br/><br/>")
return HttpResponse(assignmentOutput)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment