Commit 9e21456f authored by Chester Tan's avatar Chester Tan

created forms.py file for assignment forms

created new template for display new assignment form
added new assignment button and link to assignments page
added link to go back to assignment list page
added url routes
created function base view for new assignment form
parent af2cfc4e
from django.forms import ModelForm
from .views import Assignment
class AssignmentForm(ModelForm):
class Meta:
model = Assignment
fields = '__all__'
\ No newline at end of file
{% extends 'base.html' %}
{% block content %}
<h1>New Assignment</h1>
<form method="POST">
{% csrf_token %}
{{form.as_p}}
<input type="submit" value="Save Assignment">
</form>
<a href="{% url 'assignments' %}"><button>Go back</button></a>
{% endblock content %}
......@@ -11,3 +11,4 @@
{% load static %}
<li><img src="{% static 'assignments/chesterC.png' %}" alt="image"></li>
</ul>
<a href="{% url 'assignments' %}"><button>Go back</button></a>
\ No newline at end of file
......@@ -13,5 +13,6 @@
{% endfor %}
</ul>
{% endfor %}
<a href="{% url 'assignment-add' %}"><button>New Assignment</button></a>
</ul>
{% endblock content %}
\ No newline at end of file
from django.urls import path
from .views import AssignmentDetailView, AssignmentListView
from .views import AssignmentDetailView, AssignmentListView, assignmentCreate
urlpatterns = [
path('', AssignmentListView.as_view(), name='assignments'),
path('<int:pk>/details/', AssignmentDetailView.as_view(), name='assignment-detail'),
path('add/', assignmentCreate, name='assignment-add'),
]
\ No newline at end of file
from django.shortcuts import render
from django.shortcuts import render, redirect
from .models import Assignment, Course
from django.views.generic.detail import DetailView
from django.views.generic.list import ListView
from django.views.generic.edit import CreateView
from .forms import AssignmentForm
class AssignmentListView(ListView):
model = Course
......@@ -12,4 +14,19 @@ class AssignmentListView(ListView):
return context
class AssignmentDetailView(DetailView):
model = Assignment
\ No newline at end of file
model = Assignment
def assignmentCreate(request):
form = AssignmentForm()
context = {
'form':form,
}
if request.method == 'POST':
form = AssignmentForm(request.POST)
if form.is_valid():
form.save()
return redirect('/assignments')
return render(request, 'assignments/assignment_add.html', context)
\ 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