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 @@ ...@@ -16,7 +16,7 @@
<img src="{% static 'assignment1.jpg' %}"> <img src="{% static 'assignment1.jpg' %}">
{% elif assignment.id == 2 %} {% elif assignment.id == 2 %}
<img src="{% static 'assignment2.jpg' %}"> <img src="{% static 'assignment2.jpg' %}">
{% else %} {% elif assigment.id == 3 %}
<img src="{% static 'code.jpg' %}"> <img src="{% static 'code.jpg' %}">
{% endif %} {% endif %}
......
...@@ -24,5 +24,5 @@ ...@@ -24,5 +24,5 @@
</li> </li>
{% endfor %} {% endfor %}
</ul> </ul>
<a class="assignment-button" href="/assignment/add">New Assignment</a> <a class="assignment-button" href="/assignments/add">New Assignment</a>
{% endblock %} {% 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 django.urls import path
from .views import index, AssignmentDetailView from .views import index, AssignmentDetailView, new_assignment
urlpatterns = [ urlpatterns = [
path('', index, name='index'), 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' 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.http import HttpResponse
from django.template import loader from django.template import loader
from django.views.generic.detail import DetailView from django.views.generic.detail import DetailView
from .models import Assignment, Course from .models import Assignment, Course
from .forms import AssignmentForm
# Create your views here. # Create your views here.
...@@ -15,4 +16,14 @@ def index(request): ...@@ -15,4 +16,14 @@ def index(request):
return HttpResponse(template.render(context, request)) return HttpResponse(template.render(context, request))
class AssignmentDetailView(DetailView): class AssignmentDetailView(DetailView):
model = Assignment model = Assignment
\ No newline at end of file
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
...@@ -25,4 +25,10 @@ img { ...@@ -25,4 +25,10 @@ img {
color: white; color: white;
padding: 8px 24px; padding: 8px 24px;
text-decoration: none; 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