Commit b99e11d4 authored by Chester Tan's avatar Chester Tan

added Course model to admin panel

updated Assignments view to display course/section
parent 3643c1e7
from django.contrib import admin from django.contrib import admin
from .models import Assignment from .models import Assignment, Course
class AssignmentAdmin(admin.ModelAdmin): class AssignmentAdmin(admin.ModelAdmin):
model = Assignment model = Assignment
class CourseAdmin(admin.ModelAdmin):
model = Course
admin.site.register(Assignment, AssignmentAdmin) admin.site.register(Assignment, AssignmentAdmin)
\ No newline at end of file admin.site.register(Course, CourseAdmin)
\ No newline at end of file
# Generated by Django 4.0.3 on 2022-03-22 06:12 # Generated by Django 4.0.3 on 2022-03-31 07:22
from django.db import migrations, models from django.db import migrations, models
...@@ -15,9 +15,18 @@ class Migration(migrations.Migration): ...@@ -15,9 +15,18 @@ class Migration(migrations.Migration):
name='Assignment', name='Assignment',
fields=[ fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=10)), ('name', models.CharField(max_length=30)),
('description', models.TextField(max_length=500)), ('description', models.TextField(max_length=500)),
('max_points', models.IntegerField()), ('max_points', models.IntegerField()),
], ],
), ),
migrations.CreateModel(
name='Course',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('course_code', models.SlugField(max_length=10)),
('course_title', models.SlugField(max_length=100)),
('section', models.CharField(max_length=3)),
],
),
] ]
# Generated by Django 4.0.3 on 2022-03-31 07:33
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('assignments', '0002_alter_assignment_name'),
]
operations = [
migrations.AddField(
model_name='assignment',
name='course',
field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, related_name='assignment', to='assignments.course'),
preserve_default=False,
),
]
from django.db import models from django.db import models
class Course(models.Model):
course_code = models.SlugField(max_length=10)
course_title = models.SlugField(max_length=100)
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=30) name=models.CharField(max_length=30)
description=models.TextField(max_length=500) description=models.TextField(max_length=500)
max_points=models.IntegerField() max_points=models.IntegerField()
course=models.ForeignKey(
Course,
on_delete=models.CASCADE,
related_name='assignment'
)
def __str__(self): def __str__(self):
return self.name return self.name
...@@ -11,8 +24,3 @@ class Assignment(models.Model): ...@@ -11,8 +24,3 @@ class Assignment(models.Model):
@property @property
def passing_score(self): def passing_score(self):
return int(self.max_points*.6) return int(self.max_points*.6)
class Course(models.Model):
course_code = models.SlugField(max_length=10)
course_title = models.SlugField(max_length=100)
section = models.CharField(max_length=3)
\ No newline at end of file
...@@ -3,5 +3,6 @@ ...@@ -3,5 +3,6 @@
<p>Assignment Name: {{assignment.name}}</p> <p>Assignment Name: {{assignment.name}}</p>
<p>Description: {{assignment.description}}</p> <p>Description: {{assignment.description}}</p>
<p>Perfect Score: {{assignment.max_points}}</p> <p>Perfect Score: {{assignment.max_points}}</p>
<p>Passing Score: {{assignment.passing_score}}</p><br> <p>Passing Score: {{assignment.passing_score}}</p>
<p>Course/Section: {{assignment.course.course_code}}-{{assignment.course.course_title}}-{{assignment.course.section}}</p><br>
{% endfor %} {% endfor %}
\ 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