Commit 96826a45 authored by Vaughn Fajardo's avatar Vaughn Fajardo

feat: image featureu for assignments form

parent b8471c6d
......@@ -4,4 +4,4 @@ from .models import Assignment, Course
class AssignmentForm(ModelForm):
class Meta:
model = Assignment
fields = ["name", "description", "max_points", "course"]
\ No newline at end of file
fields = ["name", "description", "max_points", "course", "image"]
\ No newline at end of file
# Generated by Django 4.0.3 on 2022-05-24 08:34
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('assignments', '0006_alter_assignment_image'),
]
operations = [
migrations.AlterField(
model_name='assignment',
name='image',
field=models.FileField(null=True, upload_to='static/assignments'),
),
]
......@@ -16,7 +16,7 @@ class Assignment(models.Model):
description = models.CharField(max_length=500)
max_points = models.IntegerField(default=0)
passing_score = models.IntegerField(default=0)
image = models.FileField(upload_to='static/assignments/', null=True)
image = models.FileField(upload_to='static/assignments', null=True)
def __str__(self):
return self.name
......
......@@ -5,7 +5,7 @@
{% block content %}
<h1>New Assignment</h1>
<a href="{% url 'assignments:index' %}">Assignments Per Course</a>
<form method="POST" action="{% url 'assignments:newassignment' %}">
<form method="POST" action="{% url 'assignments:newassignment' %}" enctype="multipart/form-data">
{% csrf_token %}
{{ assignment_form.as_p }}
<button class="button" type="submit">Save Assignment</button>
......
......@@ -32,7 +32,7 @@ def details(request, assignment_id):
def newassignment(request):
if request.method == "POST":
assignment_form = AssignmentForm(request.POST)
assignment_form = AssignmentForm(request.POST, request.FILES)
if assignment_form.is_valid():
new_assignment = assignment_form.save()
return redirect("assignments:newassignment")
......
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