Commit 2e157fd0 authored by Nate Brevin A. Que's avatar Nate Brevin A. Que

Updated str function of Assignment model, and views.pyto make the code cleaner.

parent 3ec21087
# Generated by Django 3.2 on 2023-03-06 11:36
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('assignments', '0001_initial'),
]
operations = [
migrations.RemoveField(
model_name='assignment',
name='passing_score',
),
]
...@@ -15,7 +15,15 @@ class Assignment(models.Model): ...@@ -15,7 +15,15 @@ class Assignment(models.Model):
description = models.TextField() description = models.TextField()
course = models.ForeignKey(Course, on_delete=models.CASCADE) course = models.ForeignKey(Course, on_delete=models.CASCADE)
perfect_score = models.IntegerField() perfect_score = models.IntegerField()
passing_score = models.IntegerField()
def __str__(self): def __str__(self):
return self.name return """Assignment Name: {}<br>
\ No newline at end of file Description: {}<br>
Perfect Score: {}<br>
Passing Score: {}<br>
Course/Section: {}<br>""".format(self.name, self.description, self.perfect_score,
self.passing_score, self.course)
@property
def passing_score(self):
return round(self.perfect_score*6/10)
\ 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 .models import Course, Assignment from .models import Assignment
def index(request): def index(request):
page_content="""<H1>Widget's Assignments Page</H1>""" page_content = "<H1>Widget's Assignments Page</H1><ul>"
for assignment in Assignment.objects.all(): for assignment in Assignment.objects.all():
page_content += """<ul> page_content += "<li>{}<br>".format(assignment)
<li>Assignment Name: {}<br>
<li>Description: {}<br>
<li>Perfect Score: {}<br>
<li>Passing Score: {}<br>
<li>Course/Section: {}<br>
</ul>""".format(assignment.name, assignment.description,
assignment.perfect_score, assignment.passing_score,
assignment.course)
return HttpResponse(page_content) return HttpResponse(page_content)
\ 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