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): ...@@ -14,7 +14,7 @@ class Course(models.Model):
) )
def __str__(self): def __str__(self):
return self.course_code + " - " + self.course_title return self.course_code + " - " + self.course_title +" | " + self.section
class Assignment(models.Model): class Assignment(models.Model):
name = models.CharField(max_length=50) name = models.CharField(max_length=50)
...@@ -26,6 +26,11 @@ class Assignment(models.Model): ...@@ -26,6 +26,11 @@ class Assignment(models.Model):
default=None, default=None,
null=True null=True
) )
image = models.ImageField(
null=True,
blank=True,
upload_to="images/"
)
def __str__(self): def __str__(self):
return self.name 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 @@ ...@@ -9,12 +9,8 @@
{{assignment.max_points}} <br> {{assignment.max_points}} <br>
{{assignment.passing_score}} <br> {{assignment.passing_score}} <br>
{% if assignment.id == 1 %} {% if assignment.image %}
<img src = "{% static 'assignments/images/history.jpg' %}" alt = "history"> <img src="{{ assignment.image.url }}">
{% elif assignment.id == 2 %}
<img src = "{% static 'assignments/images/koreanlang.png' %}" alt = "korean speaking">
{% else %}
<img src = "{% static 'assignments/images/yoga.jpg' %}" alt = "yoga">
{% endif %} {% endif %}
......
...@@ -19,8 +19,7 @@ ...@@ -19,8 +19,7 @@
{% endfor %} {% endfor %}
</p> </p>
<button type="button"> <a href="{% url 'assignments:add' %}" id="new"> New Assignment</a> </button>
{% endblock %} {% endblock %}
......
...@@ -6,6 +6,8 @@ urlpatterns = [ ...@@ -6,6 +6,8 @@ urlpatterns = [
path('', views.index, name = 'index'), path('', views.index, name = 'index'),
#assignments/1/details #assignments/1/details
path("<int:assignment_id>/details/", views.detail, name='detail'), path("<int:assignment_id>/details/", views.detail, name='detail'),
#assignments/add
path("add/", views.add, name='add'),
] ]
app_name = "assignments" app_name = "assignments"
\ No newline at end of file
...@@ -2,6 +2,8 @@ from unicodedata import name ...@@ -2,6 +2,8 @@ from unicodedata import name
from django.http import Http404, HttpResponse from django.http import Http404, HttpResponse
from django.shortcuts import render, redirect from django.shortcuts import render, redirect
from .models import Course, Assignment from .models import Course, Assignment
from .forms import AssignmentForm
# Create your views here. # Create your views here.
...@@ -18,3 +20,15 @@ def detail(request, assignment_id): ...@@ -18,3 +20,15 @@ def detail(request, assignment_id):
except Assignment.DoesNotExist: except Assignment.DoesNotExist:
raise Http404("Assignment does not exist!") raise Http404("Assignment does not exist!")
return render(request, "assignments/detail.html", {"assignment": assignment}) 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/' ...@@ -132,3 +132,10 @@ STATIC_URL = '/static/'
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field # https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' 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 ...@@ -15,6 +15,8 @@ Including another URLconf
""" """
from django.contrib import admin from django.contrib import admin
from django.urls import include, path from django.urls import include, path
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [ urlpatterns = [
path('assignments/', include('assignments.urls', namespace="assignments")), path('assignments/', include('assignments.urls', namespace="assignments")),
...@@ -22,4 +24,5 @@ urlpatterns = [ ...@@ -22,4 +24,5 @@ urlpatterns = [
path("homepage/", include('homepage.urls', namespace="homepage")), path("homepage/", include('homepage.urls', namespace="homepage")),
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
path('announcements/', include('announcements.urls', namespace="announcements")), 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