Commit 42fc05cd authored by jmAmador's avatar jmAmador

working assignments page

need to fix the assignments and course models' relationships
parent cf959f2e
from django.contrib import admin from django.contrib import admin
from .models import Assignments, Course
# Register your models here. # Register your models here.
class AssignmentsAdmin(admin.ModelAdmin):
model = Assignments
class CourseAdmin(admin.ModelAdmin):
model = Course
admin.site.register(Assignments, AssignmentsAdmin)
admin.site.register(Course, CourseAdmin)
# Generated by Django 4.1.7 on 2023-03-01 08:40
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('Assignments', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='Assignments',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=100)),
('description', models.CharField(max_length=10000)),
('course', models.CharField(max_length=10000)),
],
),
migrations.CreateModel(
name='Course',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('code', models.CharField(max_length=10)),
('title', models.CharField(max_length=10000)),
('section', models.CharField(max_length=3)),
],
),
migrations.DeleteModel(
name='IndexCard',
),
]
# Generated by Django 4.1.7 on 2023-03-01 08:58
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('Assignments', '0002_assignments_course_delete_indexcard'),
]
operations = [
migrations.AddField(
model_name='assignments',
name='perfect_score',
field=models.IntegerField(default=10),
preserve_default=False,
),
]
from django.db import models from django.db import models
from django.urls import reverse
# Create your models here. # Create your models here.
...@@ -7,10 +8,27 @@ class Assignments(models.Model): ...@@ -7,10 +8,27 @@ class Assignments(models.Model):
description = models.CharField(max_length=10000) description = models.CharField(max_length=10000)
course = models.CharField(max_length=10000) course = models.CharField(max_length=10000)
perfect_score = models.IntegerField() perfect_score = models.IntegerField()
passing_score = perfect_score*0.6
def __str__(self):
return '{}: {}'.format(self.name, self.course)
def get_absolute_url(self):
return reverse('perfect_score_detail', args=[str(self.perfect_score)])
@property
def passing_score(self):
p_score = float(self.perfect_score)
return p_score*0.6
class Course(models.Model): class Course(models.Model):
code = models.CharField(max_length=10) code = models.CharField(max_length=10)
title = models.CharField(max_length=10000) title = models.CharField(max_length=10000)
section = models.CharField(max_length=3) section = models.CharField(max_length=3)
def __str__(self):
return '{}: {}: Section {}'.format(self.code, self.title, self.section)
def get_absolute_url(self):
return reverse('course_detail', args=[str(self.section)])
from django.shortcuts import render from django.shortcuts import render
from django.http import HttpResponse from django.http import HttpResponse
from django.template import loader
from .models import Assignments, Course
# Create your view here. # Create your view here.
def index(request): def index(request):
return HttpResponse('Hello World! This came from the Assignments view') overall_assignments = "<html><title>Assignments</title><body>" \
"<h1> Widget's Assignments Page!</h1>"
for assignment in Assignments.objects.all():
overall_assignments += "<li>Assignment Name: %s<br>" %assignment.name
overall_assignments += "Description: %s<br>" %assignment.description
overall_assignments += "Perfect Score: %i<br>" %assignment.perfect_score
perfect_s = float(assignment.perfect_score)
overall_assignments += "Passing Score: %i" %(float(perfect_s)*0.6)
"""overall_assignments += "Course/Section: %s %s %s" %assignment.course.code %assignment.course.title %assignment.course.section"""
overall_assignments += "</body></html>"
return HttpResponse(overall_assignments)
\ No newline at end of file
No preview for this file type
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