Commit 0eb6540c authored by Ysabella Panghulan's avatar Ysabella Panghulan

Merged widget_assignments branch to main

parents 80abf5e8 2c33d930
from django.contrib import admin
from .models import Assignment, Course
# Register your models here.
class AssignmentInLine(admin.TabularInline):
model = Assignment
class CourseAdmin(admin.ModelAdmin):
model = Course
list_display = ('code', 'title', 'section')
search_fields = ('code', 'title', 'section')
inlines = [AssignmentInLine]
class AssignmentAdmin(admin.ModelAdmin):
list_display = ('name', 'description', 'course', 'perfect_score', 'passing_score')
def get_name(self, obj):
return obj.assignment.name
get_name.short_description = 'name'
admin.site.register(Assignment, AssignmentAdmin)
admin.site.register(Course, CourseAdmin)
from django.apps import AppConfig
class AssignmentsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'assignments'
# Generated by Django 4.1.7 on 2023-03-05 05:46
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Course',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('code', models.CharField(max_length=10)),
('title', models.CharField(max_length=50)),
('section', models.CharField(max_length=3)),
],
),
migrations.CreateModel(
name='Assignment',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=50)),
('description', models.TextField(max_length=500)),
('perfect_score', models.IntegerField(default=0)),
('course', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='assignments.course')),
],
),
]
from django.db import models
# Create your models here.
class Course(models.Model):
code = models.CharField(max_length=10)
title = models.CharField(max_length=50)
section = models.CharField(max_length=3)
def __str__(self):
return self.code
class Assignment(models.Model):
name = models.CharField(max_length=50)
description = models.TextField(max_length=500)
course = models.ForeignKey(Course, on_delete=models.CASCADE)
perfect_score = models.IntegerField(default=0)
@property
def passing_score(self):
return round(self.perfect_score*0.6)
def __str__(self):
return self.name
\ No newline at end of file
from django.test import TestCase
# Create your tests here.
from django.urls import path
from . import views
urlpatterns = [
path('', views.assignments, name = "assignments"),
]
\ No newline at end of file
from django.http import HttpResponse
from .models import Assignment, Course
# Create your views here.
def assignments(request):
homeworks = Assignment.objects.all()
display = 'Widget\'s Assignments Page<br><br>'
for homework in homeworks:
assignment_name = homework.name
assignment_description = homework.description
assignment_perfect_score = homework.perfect_score
assignment_passing_score = homework.passing_score
course_code = homework.course.code
course_title = homework.course.title
course_section = homework.course.section
display += 'Assignment Name: ' + assignment_name + '<br>'
display += 'Description: ' + assignment_description + '<br>'
display += 'Perfect Score: ' + str(assignment_perfect_score) + '<br>'
display += 'Passing Score: ' + str(assignment_passing_score) + '<br>'
display += 'Course/Section: ' + course_code + ' ' + course_title + '-' + course_section + '<br><br>'
return HttpResponse(display)
\ No newline at end of file
......@@ -35,7 +35,6 @@ ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'forum',
'dashboard',
'django.contrib.admin',
'django.contrib.auth',
......
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