Commit 1da508fa authored by Angelico Ruiz T. Teaño's avatar Angelico Ruiz T. Teaño

Merge branch 'teano/assignments'

parents 85df01f9 778a96ee
from django.contrib import admin from django.contrib import admin
# Register your models here. # Register your models here.
from .models import Assignment from .models import Assignment, Course
class CourseAdmin(admin.ModelAdmin):
model = Course
search_fields = ['course_code', 'course_title', 'section']
list_display = ('course_code', 'course_title', 'section')
class AssignmentAdmin(admin.ModelAdmin): class AssignmentAdmin(admin.ModelAdmin):
model = Assignment model = Assignment
search_fields = ['name', 'description'] search_fields = ['name', 'description', 'course']
list_display = ('name', 'description', 'max_points') list_display = ('name', 'description', 'passing_score', 'max_points', 'course')
admin.site.register(Course, CourseAdmin)
admin.site.register(Assignment, AssignmentAdmin) admin.site.register(Assignment, AssignmentAdmin)
\ No newline at end of file
# Generated by Django 4.0.3 on 2022-04-02 09:34
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('assignments', '0002_alter_assignment_description'),
]
operations = [
migrations.AddField(
model_name='assignment',
name='passing_score',
field=models.IntegerField(default=0, editable=False),
),
]
# Generated by Django 4.0.3 on 2022-04-02 10:51
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('assignments', '0003_assignment_passing_score'),
]
operations = [
migrations.CreateModel(
name='Course',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('course_code', models.CharField(max_length=10)),
('course_title', models.CharField(max_length=50)),
('section', models.CharField(max_length=3)),
],
),
migrations.AddField(
model_name='assignment',
name='course',
field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, to='assignments.course'),
),
]
from django.db import models from django.db import models
# Create your models here. # Create your models here.
class Course(models.Model):
course_code = models.CharField(max_length=10)
course_title = models.CharField(max_length=50)
section = models.CharField(max_length=3)
def __str__(self):
return self.course_code
class Assignment(models.Model): class Assignment(models.Model):
name = models.CharField(max_length=50) name = models.CharField(max_length=50)
description = models.TextField(max_length=1500) description = models.TextField(max_length=1500)
max_points = models.IntegerField(default=0) max_points = models.IntegerField(default=0)
passing_score = models.IntegerField(default=0, editable=False)
course = models.ForeignKey(Course, on_delete=models.CASCADE, default=1)
def __str__(self): def __str__(self):
return self.name return self.name
# Overrides save method to update passing_score value to 60% of max_points
def save(self, *args, **kwargs):
self.passing_score = int(self.max_points*0.6)
return super().save(*args, **kwargs)
\ No newline at end of file
from django.http import HttpResponse from django.http import HttpResponse
from .models import Assignment
# Create your views here. # Create your views here.
def index(request): def index(request):
return HttpResponse("This is the Assignments page!") return HttpResponse(display_assignments(Assignment.objects.all()))
\ No newline at end of file
def display_assignments(data_set_assignment):
display_output = "ASSIGNMENTS: <br>"
for object in data_set_assignment:
display_output += '''
Assignment Name: {name}<br>
Description: {description}<br>
Perfect Score: {max_points}<br>
Passing Score: {passing_score}<br>
Course/Section: {course_code} | {course_title} - {section}<br><br>
'''.format(name = object.name,
description = object.description,
max_points = object.max_points,
passing_score = object.passing_score,
course_code = object.course.course_code,
course_title = object.course.course_title,
section = object.course.section)
return display_output
\ No newline at end of file
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