Commit 743f1df0 authored by Paul Angelo Sy's avatar Paul Angelo Sy

Added forms feature on Assignments

parent 653c019a
from django.forms import ModelForm
from .models import Assignment
class AssignmentForm(ModelForm):
class Meta:
model = Assignment
fields = ["name", "description", "max_points", "course_code"]
{% extends 'base.html' %}
{% block head %}
{% load static %}
<link rel="stylesheet" type="text/css" href="{% static 'assignments/style.css' %}">
{% endblock %}
{% block content %}
<h1> New Assignment </h1>
<form action="{% url 'assignments:newAssignment' %}" method ="POST">
{% csrf_token %}
{{assignment_form.as_p}}
<button class="button" type="submit">Save Assignment</button>
</form>
<a href="/assignments/"> <button>Back to Assignments</button> </a>
{% endblock %}
......@@ -9,5 +9,7 @@
<li> Description: {{assignment.description}} </li>
<li> Perfect Score: {{assignment.max_points}} </li>
<li> Passing Score: {{assignment.passing_score}} </li>
<a href="/assignments/"> <button>Back to Assignments</button> </a>
<br>
<img src= "/static/assignments/{{assignment.name}}.jpg">
{% endblock %}
......@@ -17,6 +17,7 @@
{% endfor %}
</li>
{% endfor %}
<a href="/assignments/newAssignment"> <button>Create an Assignment</button> </a>
{% else %}
<p>No assignments are available </p>
{% endif %}
......
......@@ -2,7 +2,9 @@ from django.urls import path
from . import views
app_name="assignments"
urlpatterns = [
path('', views.index, name="assignments"),
path("<int:assignment_id>/details", views.detail, name = "details"),
path('newAssignment', views.newAssignment, name="newAssignment")
]
from django.http import HttpResponse, Http404
from assignments.models import Assignment, Course
from django.shortcuts import render
from django.shortcuts import render, redirect
from django.template import loader
from .forms import AssignmentForm
# Create your views here.
def index(request):
......@@ -27,3 +28,13 @@ def detail(request, assignment_id):
"course": course
}
return HttpResponse (template.render(context, request))
def newAssignment(request):
if request.method == "POST":
assignment_form = AssignmentForm(request.POST)
if assignment_form.is_valid():
assignment_form.save()
return redirect("assignments:newAssignment")
else:
assignment_form = AssignmentForm()
return render(request, "assignments/add.html", {"assignment_form": AssignmentForm})
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