Commit d942df4c authored by kylemendozaa's avatar kylemendozaa

updated index view for assignhments

parent 151f0b35
...@@ -10,7 +10,7 @@ class Assignment(models.Model): ...@@ -10,7 +10,7 @@ class Assignment(models.Model):
description = models.TextField() description = models.TextField()
max_points = models.IntegerField(default=10) max_points = models.IntegerField(default=10)
passing_score = models.IntegerField(default=6) passing_score = models.IntegerField(default=6)
course = models.ForeignKey(Course, on_delete=models.CASCADE, null=True) course = models.ForeignKey(Course, on_delete=models.CASCADE, null=True, related_name="assignments")
def save(self): def save(self):
self.passing_score = int(0.6*self.max_points) self.passing_score = int(0.6*self.max_points)
......
{% extends 'base.html' %}
{% load static %}
{% block title %}Assignments{% endblock %}
{% block styles %}
<link rel="stylesheet" href="{% static 'assignments.css' %}">
{% endblock %}
{% block content %}
<h1>Assignments Per Course</h1>
<h2>List of courses: </h2>
<ul>
{% for course in courses %}
<li>
<p>{{ course.course_code }} {{ course.course_title }} {{ course.section }}</p>
<ul>
{% for assignment in course.assignments.all %}
<li>
<a href="assignments/{{ assignment.id }}/details">{{ assignment.name }}</a>
</li>
{% endfor %}
</ul>
</li>
{% endfor %}
</ul>
{% endblock %}
\ No newline at end of file
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 Assignment from .models import Assignment, Course
# Create your views here. # Create your views here.
def index(request): def index(request):
formatted_assignments = "ASSIGNMENTS:<br>" context = {
"courses": Course.objects.order_by("course_code"),
for assignment in Assignment.objects.all(): }
formatted_assignments += assignment.getAssignment() + "<br>" template = loader.get_template("assignments/index.html")
return HttpResponse(template.render(context, request))
return HttpResponse(formatted_assignments) \ No newline at end of file
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