Commit a7f77bfc authored by jmAmador's avatar jmAmador

fully working assignments app

found a solution to the assignments and course models' relationship
parent 42fc05cd
# Generated by Django 4.1.7 on 2023-03-02 20:44
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('Assignments', '0003_assignments_perfect_score'),
]
operations = [
migrations.AddField(
model_name='assignments',
name='course_stuff',
field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, to='Assignments.course'),
preserve_default=False,
),
]
...@@ -3,32 +3,26 @@ from django.urls import reverse ...@@ -3,32 +3,26 @@ from django.urls import reverse
# Create your models here. # Create your models here.
class Course(models.Model):
code = models.CharField(max_length=10)
title = models.CharField(max_length=10000)
section = models.CharField(max_length=3)
def __str__(self):
return '{} {} {}'.format(self.code, self.title, self.section)
def get_absolute_url(self):
return reverse('course_detail', args=[str(self.section)])
class Assignments(models.Model): class Assignments(models.Model):
name = models.CharField(max_length=100) name = models.CharField(max_length=100)
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()
course_stuff = models.ForeignKey(Course, on_delete=models.CASCADE)
def __str__(self): def __str__(self):
return '{}: {}'.format(self.name, self.course) return '{}: {}'.format(self.name, self.course)
def get_absolute_url(self): def get_absolute_url(self):
return reverse('perfect_score_detail', args=[str(self.perfect_score)]) 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):
code = models.CharField(max_length=10)
title = models.CharField(max_length=10000)
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.http import HttpResponse from django.http import HttpResponse
from django.template import loader from .models import Assignments
from .models import Assignments, Course
# Create your view here. # Create your view here.
...@@ -10,12 +8,12 @@ def index(request): ...@@ -10,12 +8,12 @@ def index(request):
overall_assignments = "<html><title>Assignments</title><body>" \ overall_assignments = "<html><title>Assignments</title><body>" \
"<h1> Widget's Assignments Page!</h1>" "<h1> Widget's Assignments Page!</h1>"
for assignment in Assignments.objects.all(): for assignment in Assignments.objects.all():
overall_assignments += "<li>Assignment Name: %s<br>" %assignment.name overall_assignments += "<p><b>Assignment Name: %s</b><br>" %assignment.name
overall_assignments += "Description: %s<br>" %assignment.description overall_assignments += "Description: %s<br>" %assignment.description
overall_assignments += "Perfect Score: %i<br>" %assignment.perfect_score overall_assignments += "Perfect Score: %i<br>" %assignment.perfect_score
perfect_s = float(assignment.perfect_score) perfect_s = float(assignment.perfect_score)
overall_assignments += "Passing Score: %i" %(float(perfect_s)*0.6) overall_assignments += "Passing Score: %i<br>" %(float(perfect_s)*0.6)
"""overall_assignments += "Course/Section: %s %s %s" %assignment.course.code %assignment.course.title %assignment.course.section""" overall_assignments += "Course/Section: %s" %assignment.course_stuff
overall_assignments += "</body></html>" overall_assignments += "</body></html>"
return HttpResponse(overall_assignments) 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