Fixed model relations in views

parent 6765bbad
from django.shortcuts import render from django.shortcuts import render
from django.http import HttpResponse from django.http import HttpResponse
from .models import Assignment, Course from .models import Assignment, Course
import os
def index(request): def index(request):
output = f"Widget's Assignments Page\n" output = f"Widget's Assignments Page<br><br>"
count = Assignment.objects.all().count() count = Assignment.objects.all().count()
for i in range(1, count + 1): for i in range(1, count + 1):
assignments = Assignment.objects.get(id=i) assignments = Assignment.objects.get(id=i)
courses = Course.objects.get(id=i) courses = Course.objects.get(id=i)
output += (f"Assignment Name: {assignments.name}\n" output += f"""Assignment Name: {assignments.name}<br>
f"Description: {assignments.description}\n" Description: {assignments.description}<br>
f"Perfect Score: {assignments.perfect_score}\n" Perfect Score: {assignments.perfect_score}<br>
f"Passing Score: {assignments.passing_score}\n" Passing Score: {assignments.passing_score}<br>
f"Course/Section: {courses.code} {courses.title}-{courses.section}\n\n") Course/Section: {assignments.course.code} {assignments.course.title}-{cassignments.course.section}<br>
<br>"""
return HttpResponse(output) return HttpResponse(output)
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