Commit ea117b22 authored by Adrian Lance Damalerio's avatar Adrian Lance Damalerio

Merge branch 'master' into 'dashboard_wip'

# Conflicts:
#   widget_aguandhischipmunks/widget_aguandhischipmunks/urls.py
parents 620b79a6 2fd4b41b
from django.contrib import admin
from .models import Course, Assignment
# Register your models here.
# admin panel for Course model
class CourseAdmin(admin.ModelAdmin):
model = Course
list_display = ('code', 'title', 'section')
search_fields = ('code', 'title', 'section')
list_filter = ('code', 'title', 'section')
# admin panel for Assignment model
class AssignmentAdmin(admin.ModelAdmin):
model = Assignment
list_display = ('name', 'description', 'course', 'perfect_score', 'passing_score')
search_fields = ('name', 'description', 'course')
list_filter = ('name', 'description', 'course', 'perfect_score')
admin.site.register(Course, CourseAdmin)
admin.site.register(Assignment, AssignmentAdmin)
\ No newline at end of file
from django.db import models
# Create your models here.
# Course
# code; title; section;
class Course(models.Model):
code = models.CharField(max_length = 10)
title = models.CharField(max_length = 100)
section = models.CharField(max_length = 3)
def __str__(self):
return self.code + " - " + self.title
# Assignments
# name; description; course; perfect_score; passing_score
class Assignment(models.Model):
name = models.CharField(max_length = 100)
description = models.CharField(max_length = 1000)
course = models.ForeignKey(Course, on_delete = models.CASCADE)
perfect_score = models.IntegerField(default = 0)
passing_score = models.IntegerField(default = 0)
def __str__(self):
return self.name
# calculates a passing score of 60% based on perfect_score
@property
def passing_score_calculated(self):
return int(self.perfect_score * 0.6)
def save(self, *args, **kwarg):
# passing_score will be updated after save()
self.passing_score = self.passing_score_calculated
super(Assignment, self).save(*args, **kwarg)
\ No newline at end of file
from django.urls import path
from . import views
# url for homepage
urlpatterns = [
path('', views.index, name='index'),
]
\ No newline at end of file
from django.shortcuts import render
from django.http import HttpResponse
from .models import Assignment, Course
# Create your views here.
def index(request):
title = "Widget's Assignments Page" + "<br><br>"
assignments = Assignment.objects.all()
# courses = Course.objects.all()
output_view = ""
for assignment in assignments:
name = "Assignment Name: " + assignment.name + "<br>"
description = "Description: " + assignment.description + "<br>"
perfect_score = "Perfect Score: " + str(assignment.perfect_score) + "<br>"
passing_score = "Passing Score: " + str(assignment.passing_score) + "<br>"
course_section = "Course/Section: " + assignment.course.code + " " + assignment.course.title + "-" + assignment.course.section + "<br><br>"
output_view = output_view + name + description + perfect_score + passing_score + course_section
return HttpResponse(title + output_view)
\ No newline at end of file
......@@ -14,9 +14,10 @@ Including another URLconf
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import include, path
from django.urls import path, include
urlpatterns = [
path("admin/", admin.site.urls),
path("dashboard/", include("dashboard.urls", namespace="dashboard")),
path("assignments/", include("assignments.urls"))
]
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