Commit b8471c6d authored by Joan Denise Nocos's avatar Joan Denise Nocos

fix: resolving merge conflicts

parents 5fd6a621 08a18138
from django.forms import ModelForm
from .models import Assignment, Course
class AssignmentForm(ModelForm):
class Meta:
model = Assignment
fields = ["name", "description", "max_points", "course"]
\ No newline at end of file
...@@ -6,6 +6,9 @@ class Course(models.Model): ...@@ -6,6 +6,9 @@ class Course(models.Model):
course_code = models.CharField(max_length=10) course_code = models.CharField(max_length=10)
course_title = models.CharField(max_length=255) course_title = models.CharField(max_length=255)
section = models.CharField(max_length=3) section = models.CharField(max_length=3)
def __str__(self):
return self.course_code + '/' + self.course_title + '/' + self.section
class Assignment(models.Model): class Assignment(models.Model):
course = models.ForeignKey(Course, on_delete=models.CASCADE, null=True) course = models.ForeignKey(Course, on_delete=models.CASCADE, null=True)
...@@ -15,7 +18,7 @@ class Assignment(models.Model): ...@@ -15,7 +18,7 @@ class Assignment(models.Model):
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
def file(self): def file(self):
......
...@@ -21,4 +21,5 @@ ...@@ -21,4 +21,5 @@
{% else %} {% else %}
<p>No course available.</p> <p>No course available.</p>
{% endif %} {% endif %}
<a href="{% url 'assignments:newassignment' %}">New Assignment</a>
{% endblock %} {% endblock %}
\ No newline at end of file
{% extends "assignments/base.html" %}
{% block page-title %}New Assignment{% endblock %}
{% block content %}
<h1>New Assignment</h1>
<a href="{% url 'assignments:index' %}">Assignments Per Course</a>
<form method="POST" action="{% url 'assignments:newassignment' %}">
{% csrf_token %}
{{ assignment_form.as_p }}
<button class="button" type="submit">Save Assignment</button>
</form>
{% endblock %}
\ No newline at end of file
from django.urls import path from django.urls import path
from . import views from . import views
from .views import IndexView
app_name = "assignments" app_name = "assignments"
urlpatterns = [ urlpatterns = [
# assignments/ # assignments/
path('', views.index, name='index'), path('', IndexView.as_view(), name='index'),
# assignments/<assignment_id>/details/ # assignments/<assignment_id>/details/
path('<int:assignment_id>/details/', views.details, name='details'), path('<int:assignment_id>/details/', views.details, name='details'),
# assignments/add/
path('add/', views.newassignment, name='newassignment'),
] ]
\ No newline at end of file
from django.http import HttpResponse, Http404 from django.http import HttpResponse, Http404
from django.shortcuts import render from django.shortcuts import render, redirect
from django.views import View
from assignments.models import Assignment, Course from assignments.models import Assignment, Course
from assignments.forms import AssignmentForm
# Create your views here. # Create your views here.
def index(request): class IndexView(View):
course_list = Course.objects.order_by("course_code") def get(self, request):
assignment_list = Assignment.objects.all() course_list = Course.objects.order_by("course_code")
context = { assignment_list = Assignment.objects.all()
"course_list" : course_list, context = {
"assignment_list" : assignment_list, "course_list" : course_list,
} "assignment_list" : assignment_list,
return render(request, "assignments/index.html", context) }
return render(request, "assignments/index.html", context)
def details(request, assignment_id): def details(request, assignment_id):
try: try:
...@@ -27,7 +30,30 @@ def details(request, assignment_id): ...@@ -27,7 +30,30 @@ def details(request, assignment_id):
} }
return render(request, "assignments/details.html", context) return render(request, "assignments/details.html", context)
# Code from previous labs: def newassignment(request):
if request.method == "POST":
assignment_form = AssignmentForm(request.POST)
if assignment_form.is_valid():
new_assignment = assignment_form.save()
return redirect("assignments:newassignment")
else:
assignment_form = AssignmentForm()
return render(request, "assignments/newassignment.html", {"assignment_form":assignment_form})
# Code from Lab 3:
#
# def index(request):
# course_list = Course.objects.order_by("course_code")
# assignment_list = Assignment.objects.all()
# context = {
# "course_list" : course_list,
# "assignment_list" : assignment_list,
# }
# return render(request, "assignments/index.html", context)
# Code from Midterm Project and earlier labs:
# #
# def index(request): # def index(request):
# assignments_view = "ASSIGNMENTS: <br>" # assignments_view = "ASSIGNMENTS: <br>"
......
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