Add option for user to add new assignment

parent 408687f5
{% extends 'base.html' %}
{% load static %}
{% block styles %}
<link rel="stylesheet" type="text/css" href="{% static 'assignments/style.css' %}">
{% endblock %}
{% block title %}New Assignment{% endblock %}
{% block content %}
<h1>New Assignment</h1>
<div>
<form method="POST" enctype="multipart/form-data">
{% csrf_token %}
Assignment name: {{ form.name }}<br>
Description: <br>{{ form.description }}<br>
Max points: {{ form.max_points }}<br>
Course Code/Course Title/Section: {{ form.course }}<br>
Image: {{ form.assignment_image}}<br>
<input type="submit" value="Save Assignment">
</form>
</div>
{% endblock %}
\ No newline at end of file
...@@ -21,11 +21,14 @@ ...@@ -21,11 +21,14 @@
</ul> </ul>
{% endif %} {% endif %}
{% endfor %} {% endfor %}
<br><br> <br>
{% endfor %} {% endfor %}
</ul> </ul>
{% else %} {% else %}
<p>There are no assignments under any course.</p> <p>There are no assignments under any course.</p>
{% endif %} {% endif %}
<a href="{% url 'assignments:addAssignment' %}">
<button>New Assignment</button>
</a>
</div> </div>
{% endblock %} {% endblock %}
\ No newline at end of file
from django.urls import path from django.urls import path
from . import views from . import views
app_name="assignments" app_name="assignments"
urlpatterns = [ urlpatterns = [
path('', views.index, name="indexAssignments"), path('', views.index, name="indexAssignments"),
path('<int:assignment_id>/details', views.details, name="details") path('<int:assignment_id>/details', views.details, name="details"),
path('add', views.addAssignment.as_view(), name="addAssignment"),
] ]
\ No newline at end of file
from ast import Assign from django.http import Http404
from django.http import HttpResponse, Http404
from django.shortcuts import render from django.shortcuts import render
from .models import Assignment, Course from .models import Assignment, Course
from django.views.generic import CreateView
# Create your views here. # Create your views here.
def index(request): def index(request):
...@@ -22,3 +21,8 @@ def details(request, assignment_id): ...@@ -22,3 +21,8 @@ def details(request, assignment_id):
raise Http404("Assignment does not exist!") raise Http404("Assignment does not exist!")
return render(request, "assignments/detail.html", {"assignment": assignment}) return render(request, "assignments/detail.html", {"assignment": assignment})
class addAssignment(CreateView):
model = Assignment
template_name = "assignments/add.html"
fields = ['name', 'description', 'max_points', 'course', 'assignment_image']
\ 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