Per Assignment Details page has been created

parent 15477754
from django.db import models
from django.urls import reverse
# Create your models here.
class Course(models.Model):
......@@ -17,6 +18,9 @@ class Assignment(models.Model):
on_delete=models.PROTECT,
)
perfect_score = models.IntegerField()
def get_absolute_url(self):
return reverse('Assignments:assignments-details', kwargs={'pk': self.pk})
@property
def passing_score(self):
......
{% extends 'base.html' %}
{% load static %}
{% block title %} {{ object.name }}{% endblock %}
{% block content %}
<h1>{{ object.name }}</h1>
<h2>{{ object.course }}</h2>
<ul>
<li>Description: {{ object.description }}</li>
<li>Perfect Score: {{ object.perfect_score }}</li>
<li>Passing Score: {{ object.passing_score }}</li>
</ul>
<button>Edit Assignment</button>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %} Widget's Assignments {% endblock %}
{% block content %}
<h1>Welcome to Widget's Assignments </h1>
<ul>
{% for object in assignments %}
<li>
<a href="{{ object.get_absolute_url }}">{{ object.name }}</a>
</li>
{% endfor %}
</ul>
<button>
New Assignment
</button>
{% endblock %}
\ No newline at end of file
from django.urls import path
from .views import index
from .views import (AssignmentView,
AssignmentsDetailView)
urlpatterns = [
path('', index, name="index")
path('assignment/', AssignmentView, name="index"),
path('<pk>/details/', AssignmentsDetailView.as_view(), name='assignment-detail')
]
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, Course
# Create your views here.
def AssignmentView(request):
assignments = Assignment.objects.all()
context = {'assignments': assignments}
return render(request, 'Assignments/assignments.html', context)
class AssignmentsDetailView(DetailView):
model = Assignment
template_name = 'Assignments/assignment-details.html'
'''
def index(request):
head_string = "<h1>Widget's Assignment Page</h1>"
body_string = ""
......@@ -16,4 +26,5 @@ def index(request):
body_string += "</p>"
html_string = '<html><head>{}</head><body>{}</body></html>'.format(head_string, body_string)
return HttpResponse(html_string)
\ No newline at end of file
return HttpResponse(html_string)
'''
\ No newline at end of file
No preview for this file type
......@@ -62,7 +62,7 @@ ROOT_URLCONF = 'widget_gitgud.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'DIRS': [os.path.join(BASE_DIR, 'template')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
......
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