Commit 99e2be94 authored by Nate Brevin A. Que's avatar Nate Brevin A. Que

Implemented the 'Per Assignment Details Page'

parent eddb0b03
SECRET_KEY = 'django-insecure-0ne3r+4_-4wxim9e1!jkyw8%fnii1af4pc$irxf%nvrs3wp*1f'
\ No newline at end of file
from django.db import models
from django.urls import reverse
class Course(models.Model):
......@@ -24,6 +25,9 @@ class Assignment(models.Model):
Course/Section: {}<br>""".format(self.name, self.description, self.perfect_score,
self.passing_score, self.course)
def get_absolute_url(self):
return reverse('assignments:assignment-details', kwargs={'pk':self.pk})
@property
def passing_score(self):
return round(self.perfect_score*6/10)
\ No newline at end of file
{% extends 'base.html' %}
{% block title %}{{ assignment.name }}{% endblock %}
{% block content %}
<h1>{{ assignment.name }}</h1>
<h3>{{ assignment.course}}<br>
Description: {{ assignment.description }}<br>
Perfect Score: {{ assignment.perfect_score }}<br>
Passing Score: {{ assignment.passing_score }}<br>
</h3>
{% endblock %}
{% block scripts %}
<input type="submit" value="Edit Assignment">
{% endblock %}
\ No newline at end of file
......@@ -5,7 +5,7 @@
<h1>Welcome to Widget's Assignments!</h1>
<h3>
{% for assignment in assignments %}
{{ assignment.name }}<br>
<a href="{{ assignment.get_absolute_url }}">{{ assignment.name }}</a><br>
{% endfor %}
</h3>
{% endblock %}
......
from django.contrib import admin
from django.urls import path
from .views import index
from .views import index, AssignmentDetailView
urlpatterns = [
path('', index, name='index'),
path('<int:pk>/details', AssignmentDetailView.as_view(), name='assignment-details'),
]
app_name = "assignments"
\ No newline at end of file
from django.shortcuts import render
from django.http import HttpResponse
from django.views.generic.detail import DetailView
from .models import Assignment
def index(request):
return render(request, 'assignments/assignments.html', {'assignments': Assignment.objects.all()})
class AssignmentDetailView(DetailView):
model = Assignment
def get(self, request, pk):
return render(request, 'assignments/assignment-details.html', {'assignment': self.model.objects.get(pk=pk)})
\ 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