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 ...@@ -4,4 +4,4 @@ from .models import Assignment, Course
class AssignmentForm(ModelForm): class AssignmentForm(ModelForm):
class Meta: class Meta:
model = Assignment model = Assignment
fields = ["name", "description", "max_points", "course"] fields = ["name", "description", "max_points", "course", "image"]
\ No newline at end of file \ 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): ...@@ -16,7 +16,7 @@ class Assignment(models.Model):
description = models.CharField(max_length=500) description = models.CharField(max_length=500)
max_points = models.IntegerField(default=0) max_points = models.IntegerField(default=0)
passing_score = 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): def __str__(self):
return self.name return self.name
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
{% block content %} {% block content %}
<h1>New Assignment</h1> <h1>New Assignment</h1>
<a href="{% url 'assignments:index' %}">Assignments Per Course</a> <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 %} {% csrf_token %}
{{ assignment_form.as_p }} {{ assignment_form.as_p }}
<button class="button" type="submit">Save Assignment</button> <button class="button" type="submit">Save Assignment</button>
......
...@@ -32,7 +32,7 @@ def details(request, assignment_id): ...@@ -32,7 +32,7 @@ def details(request, assignment_id):
def newassignment(request): def newassignment(request):
if request.method == "POST": if request.method == "POST":
assignment_form = AssignmentForm(request.POST) assignment_form = AssignmentForm(request.POST, request.FILES)
if assignment_form.is_valid(): if assignment_form.is_valid():
new_assignment = assignment_form.save() new_assignment = assignment_form.save()
return redirect("assignments:newassignment") 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