Commit 26c273cc authored by Katrina Bernice Tan's avatar Katrina Bernice Tan

Added upload image function to Assignments

parent fdc7e519
# Generated by Django 4.0.4 on 2022-05-24 10:11
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('Assignments', '0007_alter_assignment_course'),
]
operations = [
migrations.AddField(
model_name='assignment',
name='image',
field=models.ImageField(blank=True, null=True, upload_to=''),
),
]
......@@ -18,6 +18,7 @@ class Assignment(models.Model):
on_delete = models.CASCADE,
related_name = 'requirements'
)
image = models.ImageField(null=True, blank = True)
def __str__(self):
return 'Assignment name: {} :{}'.format(self.name, self.description)
......
......@@ -12,7 +12,8 @@
<div id = "details">
<a href = "/assignments"> > Back to home </a>
<br>
<img src="{%static 'images/jokebear.png'%}">
<!-- <img src="{%static 'images/jokebear.png'%}">-->
<img src = "{{object.image.url}}">
<h5> Assignment Name: </h5>
<h3>{{object.name}} </h3>
......
......@@ -18,7 +18,7 @@
<div id = "courses" style="margin: 5em;">
<a href = "/assignments"> > Back to home </a>
<form action="{% url 'Assignments:assignment-list' %}" method = "POST" style = "padding-top: 5em;">
<form action="{% url 'Assignments:assignment-list' %}" method = "POST" style = "padding-top: 5em;" enctype = "multipart/form-data">
{% csrf_token %}
......
......@@ -28,20 +28,9 @@ class AssignmentListView(ListView):
def post(self, request, *args, **kwargs):
form = AssignmentForm(request.POST)
form = AssignmentForm(request.POST, request.FILES)
if form.is_valid():
name = form.cleaned_data.get('name')
description = form.cleaned_data.get('description')
max_points = form.cleaned_data.get('max_points')
course = form.cleaned_data.get('course')
a = Assignment(
name = name,
description=description,
max_points = max_points,
course = course,
)
a.save()
form.save()
return redirect('/assignments')
return self.get(request, *args, **kwargs)
......
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