Commit aa2c4b30 authored by AllenSkyy's avatar AllenSkyy
parents 3694283e 9e21456f
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 @@ ...@@ -11,3 +11,4 @@
{% load static %} {% load static %}
<li><img src="{% static 'assignments/chesterC.png' %}" alt="image"></li> <li><img src="{% static 'assignments/chesterC.png' %}" alt="image"></li>
</ul> </ul>
<a href="{% url 'assignments' %}"><button>Go back</button></a>
\ No newline at end of file
{% extends 'base.html' %} {% extends 'base.html' %}
{% block content %} {% block content %}
<h1>Assignmets Per Course </h1> <h1>Assignments Per Course </h1>
<label>List of Courses:</label> <label>List of Courses:</label>
<ul> <ul>
{% for course in object_list %} {% for course in object_list %}
...@@ -13,5 +13,6 @@ ...@@ -13,5 +13,6 @@
{% endfor %} {% endfor %}
</ul> </ul>
{% endfor %} {% endfor %}
<a href="{% url 'assignment-add' %}"><button>New Assignment</button></a>
</ul> </ul>
{% endblock content %} {% endblock content %}
\ No newline at end of file
from django.urls import path from django.urls import path
from .views import AssignmentDetailView, AssignmentListView from .views import AssignmentDetailView, AssignmentListView, assignmentCreate
urlpatterns = [ urlpatterns = [
path('', AssignmentListView.as_view(), name='assignments'), path('', AssignmentListView.as_view(), name='assignments'),
path('<int:pk>/details/', AssignmentDetailView.as_view(), name='assignment-detail'), 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 .models import Assignment, Course
from django.views.generic.detail import DetailView from django.views.generic.detail import DetailView
from django.views.generic.list import ListView from django.views.generic.list import ListView
from django.views.generic.edit import CreateView
from .forms import AssignmentForm
class AssignmentListView(ListView): class AssignmentListView(ListView):
model = Course model = Course
...@@ -12,4 +14,19 @@ class AssignmentListView(ListView): ...@@ -12,4 +14,19 @@ class AssignmentListView(ListView):
return context return context
class AssignmentDetailView(DetailView): class AssignmentDetailView(DetailView):
model = Assignment model = Assignment
\ No newline at end of file
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