Commit e54f958a authored by Joan Denise Nocos's avatar Joan Denise Nocos

feat: added image field to Assignment model

parent 1cc16eb5
# Generated by Django 3.2.12 on 2022-05-18 07:45
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('assignments', '0004_auto_20220406_0329'),
]
operations = [
migrations.AddField(
model_name='assignment',
name='image',
field=models.FileField(null=True, upload_to='static/'),
),
]
from django.db import models
import os
# Create your models here.
class Course(models.Model):
......@@ -12,8 +13,11 @@ class Assignment(models.Model):
description = models.CharField(max_length=500)
max_points = models.IntegerField(default=0)
passing_score = models.IntegerField(default=0)
image = models.FileField(upload_to='static/', null=True)
def _str_(self):
return self.name
\ No newline at end of file
def file(self):
value = os.path.basename(self.image.name)
return value
\ No newline at end of file
{% extends "base.html" %}
{% block page-title %}Assignment {{ assignment_id }} Details{% endblock %}
{% block content %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1">
{% comment %}
<link rel="stylesheet" type="text/css"
href="{% static 'style.css' %}">
{% endcomment %}
<title>{% block page-title %}Assignment {{ assignment_id }} Details{% endblock %}</title>
</head>
<body>
<h1>{{ course.course_code }} {{ course.course_title }} {{ course.section }}</h1>
<p>{{ assignment.name }}</p>
<p>{{ assignment.description }}</p>
<p>{{ assignment.max_points }}</p>
<p>{{ assignment.passing_score }}</p>
<p>Image Placeholder</p>
{% endblock %}
\ No newline at end of file
<p>Name: {{ assignment.name }}</p>
<p>Description: {{ assignment.description }}</p>
<p>Perfect Score: {{ assignment.max_points }}</p>
<p>Passing Score: {{ assignment.passing_score }}</p>
<img src="/static/{{ assignment.file }}" width="250" height="250">
</body>
</html>
{% extends "base.html" %}
{% block page-title %}Assignments{% endblock %}
{% block content %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1">
{% comment %}
<link rel="stylesheet" type="text/css"
href="{% static 'style.css' %}">
{% endcomment %}
<title>{% block page-title %}Assignments{% endblock %}</title>
</head>
<body>
<h1>Assignments Per Course</h1>
<h2>List of Courses:</h2>
{% if course_list %}
......@@ -11,7 +19,7 @@
<p>{{ course.course_code }} {{ course.course_title }} {{ course.section }}</p>
<ul>
{% for assignment in assignment_list %}
{% if assignment.course == course.id %}
{% if assignment.course == course %}
<li><a href="{% url 'assignments:details' assignment.id %}">{{ assignment.name }}</a></li>
{% endif %}
{% endfor %}
......@@ -21,5 +29,9 @@
{% else %}
<p>No course available.</p>
{% endif %}
{% endblock %}
</body>
</html>
......@@ -14,11 +14,30 @@ def index(request):
def details(request, assignment_id):
try:
assignment = Article.objects.get(pk=assignment_id)
assignment = Assignment.objects.get(pk=assignment_id)
except Assignment.DoesNotExist:
raise Http404("Assignment does not exist!")
context = {
"assignment" : assignment,
"course" : assignment.course,
}
return render(request, "assignments/details.html", context)
\ No newline at end of file
return render(request, "assignments/details.html", context)
# Code from previous labs:
#
# def index(request):
# assignments_view = "ASSIGNMENTS: <br>"
# schoolwork = Assignment.objects.all()
# for assignment in schoolwork:
# score = assignment.max_points
# assignment.passing_score = (score*60) // 100
# assignments_view += "Assignment Name: {}<br>Description: {}<br>Perfect Score: {}<br>Passing Score: {}<br>Course/Section: {} {} {}<br><br>".\
# format(assignment.name,
# assignment.description,
# assignment.max_points,
# assignment.passing_score,
# assignment.course.course_code,
# assignment.course.course_title,
# assignment.course.section)
#
# return HttpResponse(assignments_view)
\ 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