Commit 8da1ff9f authored by Patricia Isabella Nava's avatar Patricia Isabella Nava

Merge branch 'nava/assignments'

parents 69e51314 b3b95eda
from statistics import mode
from django.forms import ModelForm
from .models import Assignment
class AssignmentForm(ModelForm):
class Meta:
model = Assignment
fields = ["name", "description", "max_points", "course", "image"]
\ No newline at end of file
# Generated by Django 3.2.12 on 2022-05-26 11:19
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('assignments', '0002_auto_20220330_2257'),
]
operations = [
migrations.AddField(
model_name='assignment',
name='image',
field=models.ImageField(blank=True, null=True, upload_to='images/'),
),
]
......@@ -14,7 +14,7 @@ class Course(models.Model):
)
def __str__(self):
return self.course_code + " - " + self.course_title
return self.course_code + " - " + self.course_title +" | " + self.section
class Assignment(models.Model):
name = models.CharField(max_length=50)
......@@ -26,6 +26,11 @@ class Assignment(models.Model):
default=None,
null=True
)
image = models.ImageField(
null=True,
blank=True,
upload_to="images/"
)
def __str__(self):
return self.name
......
{% extends "assignments/base.html" %}
{% block content %}
<h1>Add Assignment</h1>
<form method="POST" enctype="multipart/form-data" action="{% url 'assignments:add' %}">
{% csrf_token %}
{{assignment_form.media}}
{{ assignment_form.as_p }}
<button class="button" type="submit">Save Assignment</button>
</form>
<br>
<button type="button"> <a href="{% url 'assignments:index' %}" id = "back"> Back to Main Assignments Page</a> </button>
{% endblock %}
\ No newline at end of file
......@@ -9,12 +9,8 @@
{{assignment.max_points}} <br>
{{assignment.passing_score}} <br>
{% if assignment.id == 1 %}
<img src = "{% static 'assignments/images/history.jpg' %}" alt = "history">
{% elif assignment.id == 2 %}
<img src = "{% static 'assignments/images/koreanlang.png' %}" alt = "korean speaking">
{% else %}
<img src = "{% static 'assignments/images/yoga.jpg' %}" alt = "yoga">
{% if assignment.image %}
<img src="{{ assignment.image.url }}">
{% endif %}
......
......@@ -19,8 +19,7 @@
{% endfor %}
</p>
<button type="button"> <a href="{% url 'assignments:add' %}" id="new"> New Assignment</a> </button>
{% endblock %}
......
......@@ -6,6 +6,8 @@ urlpatterns = [
path('', views.index, name = 'index'),
#assignments/1/details
path("<int:assignment_id>/details/", views.detail, name='detail'),
#assignments/add
path("add/", views.add, name='add'),
]
app_name = "assignments"
\ No newline at end of file
......@@ -2,6 +2,8 @@ from unicodedata import name
from django.http import Http404, HttpResponse
from django.shortcuts import render, redirect
from .models import Course, Assignment
from .forms import AssignmentForm
# Create your views here.
......@@ -17,4 +19,16 @@ def detail(request, assignment_id):
assignment = Assignment.objects.get(pk=assignment_id)
except Assignment.DoesNotExist:
raise Http404("Assignment does not exist!")
return render(request, "assignments/detail.html", {"assignment": assignment})
\ No newline at end of file
return render(request, "assignments/detail.html", {"assignment": assignment})
def add(request):
if request.method == "POST":
assignment_form = AssignmentForm(request.POST, request.FILES)
if assignment_form.is_valid():
new_assignment = assignment_form.save()
return redirect("assignments:add")
else:
assignment_form = AssignmentForm()
context = {"assignment_form": assignment_form}
return render(request, "assignments/add.html", context)
\ No newline at end of file
......@@ -132,3 +132,10 @@ STATIC_URL = '/static/'
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
\ No newline at end of file
......@@ -15,6 +15,8 @@ Including another URLconf
"""
from django.contrib import admin
from django.urls import include, path
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
path('assignments/', include('assignments.urls', namespace="assignments")),
......@@ -22,4 +24,5 @@ urlpatterns = [
path("homepage/", include('homepage.urls', namespace="homepage")),
path('admin/', admin.site.urls),
path('announcements/', include('announcements.urls', namespace="announcements")),
]
]+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
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