Commit 8a0f68f2 authored by Paul Angelo Sy's avatar Paul Angelo Sy

Added function to assignemnts enabling photos in adding new assignment

parent 0347c901
......@@ -4,4 +4,4 @@ from .models import Assignment
class AssignmentForm(ModelForm):
class Meta:
model = Assignment
fields = ["name", "description", "max_points", "course_code"]
fields = ["name", "description", "max_points", "course_code", "assignment_image"]
# Generated by Django 3.2.12 on 2022-05-24 14:04
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('assignments', '0018_alter_assignment_passing_score'),
]
operations = [
migrations.AddField(
model_name='assignment',
name='assignment_img',
field=models.ImageField(blank=True, null=True, upload_to=''),
),
]
# Generated by Django 3.2.12 on 2022-05-24 14:22
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('assignments', '0019_assignment_assignment_img'),
]
operations = [
migrations.AlterField(
model_name='assignment',
name='assignment_img',
field=models.ImageField(blank=True, null=True, upload_to='media/'),
),
]
# Generated by Django 3.2.12 on 2022-05-24 14:22
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('assignments', '0020_alter_assignment_assignment_img'),
]
operations = [
migrations.AlterField(
model_name='assignment',
name='assignment_img',
field=models.ImageField(blank=True, null=True, upload_to='assignemnts/'),
),
]
# Generated by Django 3.2.12 on 2022-05-24 14:27
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('assignments', '0021_alter_assignment_assignment_img'),
]
operations = [
migrations.RenameField(
model_name='assignment',
old_name='assignment_img',
new_name='assignment_image',
),
]
......@@ -16,6 +16,7 @@ class Assignment(models.Model):
max_points = models.IntegerField(default=0)
passing_score = models.IntegerField(default = 0, editable =False)
course_code = models.ForeignKey(Course, on_delete=models.CASCADE, null = True, blank = True)
assignment_image = models.ImageField(upload_to="assignemnts/", null=True, blank=True)
def save(self):
self.passing_score = int(self.max_points * 0.6)
......
......@@ -6,7 +6,7 @@
{% block content %}
<h1> New Assignment </h1>
<form action="{% url 'assignments:newAssignment' %}" method ="POST">
<form action="{% url 'assignments:newAssignment' %}" method ="POST" enctype="multipart/form-data">
{% csrf_token %}
{{assignment_form.as_p}}
<button class="button" type="submit">Save Assignment</button>
......
......@@ -11,5 +11,7 @@
<li> Passing Score: {{assignment.passing_score}} </li>
<a href="/assignments/"> <button>Back to Assignments</button> </a>
<br>
<img src= "/static/assignments/{{assignment.name}}.jpg">
{% if assignment.assignment_image %}
<img src="{{ assignment.assignment_image.url }}">
{% endif %}
{% endblock %}
from django.urls import path
from django.conf.urls.static import static
from . import views
app_name="assignments"
......
......@@ -31,7 +31,7 @@ def detail(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():
assignment_form.save()
return redirect("assignments:newAssignment")
......
# Generated by Django 3.2.12 on 2022-05-24 14:04
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('forum', '0008_post_post_img'),
]
operations = [
migrations.AlterField(
model_name='post',
name='post_img',
field=models.ImageField(blank=True, null=True, upload_to='forumimg/'),
),
]
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