Commit b18c3340 authored by kylemendozaa's avatar kylemendozaa

made new assignments form

parent 166187c4
from django.forms import ModelForm
from .models import Assignment
class AssignmentForm(ModelForm):
class Meta:
model = Assignment
fields = ["name", "description", "max_points", "course"]
\ No newline at end of file
......@@ -16,7 +16,7 @@
<img src="{% static 'assignment1.jpg' %}">
{% elif assignment.id == 2 %}
<img src="{% static 'assignment2.jpg' %}">
{% else %}
{% elif assigment.id == 3 %}
<img src="{% static 'code.jpg' %}">
{% endif %}
......
......@@ -24,5 +24,5 @@
</li>
{% endfor %}
</ul>
<a class="assignment-button" href="/assignment/add">New Assignment</a>
<a class="assignment-button" href="/assignments/add">New Assignment</a>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}Assignments{% endblock %}
{% block styles %}
<link rel="stylesheet" href="{% static 'assignments.css' %}">
{% endblock %}
{% block content %}
<h1>New Assignment</h1>
<form action="{% url 'assignments:new-assignment' %}" method="POST">
{% csrf_token %}
{{ form.as_p }}
<button class="assignment-button" type="submit">Save Assignment</button>
</form>
<button class="assignment-button"><a href="/assignments">Back to Assignments</a></button>
{% endblock %}
\ No newline at end of file
from django.urls import path
from .views import index, AssignmentDetailView
from .views import index, AssignmentDetailView, new_assignment
urlpatterns = [
path('', index, name='index'),
path('<int:pk>/details', AssignmentDetailView.as_view(), name='assignment-details')
path('<int:pk>/details/', AssignmentDetailView.as_view(), name='assignment-details'),
path('add/', new_assignment, name='new-assignment')
]
app_name = 'assignments'
\ No newline at end of file
from django.shortcuts import render
from django.shortcuts import render, redirect
from django.http import HttpResponse
from django.template import loader
from django.views.generic.detail import DetailView
from .models import Assignment, Course
from .forms import AssignmentForm
# Create your views here.
......@@ -16,3 +17,13 @@ def index(request):
class AssignmentDetailView(DetailView):
model = Assignment
def new_assignment(request):
if request.method == "POST":
form = AssignmentForm(request.POST)
if form.is_valid():
form.save()
return redirect("assignments:index")
else:
form = AssignmentForm()
return render(request, 'assignments/new_assignment.html', {"form": form})
\ No newline at end of file
No preview for this file type
......@@ -26,3 +26,9 @@ img {
padding: 8px 24px;
text-decoration: none;
}
.assignment-button a {
background-color: transparent;
color: white;
text-decoration: none;
}
\ 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