added new assignment edit, add, detail views

parent 0d7a0842
......@@ -9,20 +9,23 @@ class Course(models.Model):
section = models.CharField(max_length=3)
def __str__(self):
return '{} {} {}'.format(self.code, self.title, self.section)
return '{} {} - {}'.format(self.code, self.title, self.section)
def get_absolute_url(self):
return reverse('course_detail', args=[str(self.section)])
class Assignment(models.Model):
name = models.CharField(max_length=100)
description = models.CharField(max_length=10000)
course = models.CharField(max_length=10000)
perfect_score = models.IntegerField()
perfect_score = models.FloatField()
course_stuff = models.ForeignKey(Course, on_delete=models.CASCADE)
def passing_score(self, perfect_score):
return perfect_score * 0.6
def __str__(self):
return '{}: {}'.format(self.name, self.course)
def get_absolute_url(self):
return reverse('perfect_score_detail', args=[str(self.perfect_score)])
return reverse('Assignments:assignment-details', kwargs={'pk': self.pk})
<form method="POST" enctype="multipart/form-data">
<!-- Security token -->
{% csrf_token %}
<!-- Using the formset -->
{{ form.as_p }}
<input type="submit" value="Save New Assignment">
</form>
\ No newline at end of file
{% extends 'base.html' %}
{% block title %} {{object.title}} {% endblock %}
{% block content %}
<h1>{{ object.name }}</h1>
<p>{{ object.course_stuff }}</p>
<p>Description: {{ object.description }}</p>
<p>Perfect Score: {{ object.perfect_score }}</p>
<p>Passing Score: {{ object.passing_score }}</p>
<form action='edit' method="get" enctype="multipart/form-data">
{% csrf_token %}
<input type="submit" value="Edit Assignment">
</form>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% block title %}Edit Assignment{% endblock %}
{% block content %}
<form method="post" enctype="multipart/form-data">
<!-- Security token -->
{% csrf_token %}
<!-- Using the formset -->
{{ form.as_p }}
<input type="submit" value="Save Changes to Assignment">
</form>
{% 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>
{%for object in assignment%}
<a href="{{ object.get_absolute_url }}">{{ object.name }}</a>
<br>
{%endfor%}
<br>
<form action="/assignments/add" method="get" enctype="multipart/form-data">
<input type="submit" value="New Assignment">
</form>
<a href="/dashboard">Dashboard</a>
<br>
<a href="/announcements">Announcements</a>
<br>
<a href="/forum">Forum</a>
<br>
<a href="/calendar">Calendar</a>
<br>
{% endblock %}
\ No newline at end of file
from django.urls import path
from .views import index
from .views import index, assignments_view, AssignmentDetailView, AssignmentCreateView, AssignmentUpdateView
urlpatterns = [
path('', index, name='index'),
path('', assignments_view, name='assignments_page'),
path('<int:pk>/details/', AssignmentDetailView.as_view(), name='assignment-details'),
path('add', AssignmentCreateView.as_view(), name='assignment-add'),
path('<int:pk>/details/edit', AssignmentUpdateView.as_view(), name='assignment-edit'),
]
# This might be needed, depending on your Django version
app_name = "Assignments"
from django.http import HttpResponse
from django.shortcuts import render
from django.views.generic import CreateView, UpdateView
from django.views.generic.detail import DetailView
from .models import Assignment
# Create your view here.
......@@ -17,3 +20,30 @@ def index(request):
overall_assignments += "</body></html>"
return HttpResponse(overall_assignments)
def assignments_view(request):
assignment = Assignment.objects.all()
return render(request, 'Assignments/assignments.html', {'assignment': assignment})
class AssignmentDetailView(DetailView):
model = Assignment
template_name = 'Assignments/assignment-details.html'
class AssignmentCreateView(CreateView):
model = Assignment
fields = '__all__'
template_name = 'Assignments/assignment-add.html'
class AssignmentUpdateView(UpdateView):
# specify the model you want to use
model = Assignment
fields = '__all__'
# specify the fields
# can specify success url
# url to redirect after successfully
# updating details
template_name = 'Assignments/assignment-edit.html'
No preview for this file type
<html lang="en">
<head>
<link rel="stylesheet" href="style.css">
<title>{% block title %}My amazing site{% endblock %}</title>
{% block styles %}{% endblock %}
</head>
<body>
<div id="content">
{% block content %}{% endblock %}
</div>
{% block scripts %}{% endblock %}
</body>
</html>
\ No newline at end of file
......@@ -9,7 +9,7 @@ https://docs.djangoproject.com/en/4.1/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.1/ref/settings/
"""
import os
from pathlib import Path
# Build paths inside the project like this: BASE_DIR / 'subdir'.
......@@ -59,7 +59,7 @@ ROOT_URLCONF = 'widget_group3.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'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