Commit 6628f3ec authored by Katrina Bernice Tan's avatar Katrina Bernice Tan

Merge branch 'tan/assignments' into 'master'

Added new fields and models to Assignments, updated the View to reflect Assignment model

See merge request !10
parents ddfbc71c 374342e1
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
admin.site.register(Assignment) #class CourseInline(admin.TabularInline):
\ No newline at end of file # model = Course
class AssignmentAdmin(admin.ModelAdmin):
model = Assignment
search_fields = ('name', 'max_points',)
list_display = ('name', 'max_points', 'description', 'passing_score')
list_filter = ('name', 'max_points',)
# inlines = [CourseInline,]
#admin.site.register(Course)
admin.site.register(Assignment, AssignmentAdmin)
# Generated by Django 4.0.3 on 2022-03-26 17:10
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('Assignments', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='assignment',
name='passing_score',
field=models.IntegerField(default=1),
preserve_default=False,
),
]
# Generated by Django 4.0.3 on 2022-03-26 17:42
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('Assignments', '0002_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=20)),
('section', models.CharField(max_length=3)),
],
),
migrations.RemoveField(
model_name='assignment',
name='passing_score',
),
migrations.AddField(
model_name='assignment',
name='section',
field=models.ForeignKey(default=69, on_delete=django.db.models.deletion.CASCADE, related_name='requirements', to='Assignments.course'),
preserve_default=False,
),
]
# Generated by Django 4.0.3 on 2022-03-26 17:44
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('Assignments', '0003_course_remove_assignment_passing_score_and_more'),
]
operations = [
migrations.RenameField(
model_name='assignment',
old_name='section',
new_name='Course',
),
]
# Generated by Django 4.0.3 on 2022-03-26 17:44
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('Assignments', '0004_rename_section_assignment_course'),
]
operations = [
migrations.RenameField(
model_name='assignment',
old_name='Course',
new_name='course',
),
]
# Generated by Django 4.0.3 on 2022-03-26 17:51
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('Assignments', '0005_rename_course_assignment_course'),
]
operations = [
migrations.AlterField(
model_name='assignment',
name='course',
field=models.ForeignKey(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 = 20)
section = models.CharField(max_length = 3)
def __str__(self):
return '{} {} {} '.format(self.course_code, self.course_title, self.section)
class Assignment(models.Model): class Assignment(models.Model):
name = models.CharField(max_length = 69) name = models.CharField(max_length = 69)
description = models.CharField(max_length=420) description = models.CharField(max_length=420)
max_points = models.IntegerField() max_points = models.IntegerField()
course = models.ForeignKey(
Course,
on_delete = models.CASCADE,
related_name = 'requirements'
)
def __str__(self):
return 'Assignment name: {} :{}'.format(self.name, self.description)
@property
def passing_score(self):
#return self.passing_score == 69
return self.max_points*.6
from django.shortcuts import render from django.shortcuts import render
from django.http import HttpResponse from django.http import HttpResponse
from .models import Assignment, Course
def index(request): def index(request):
return HttpResponse('This is the Assignments page!')
print = "ANNOUNCEMENTS: "
assignments = Assignment.objects.all()
for i in assignments:
#print += "Assignment Name: " + i.name + "\n Description + " + i.description + "\n Perfect Score + " + str(i.max_points) + "\n Passing Score: " + str(i.passing_score) + "\n Course/Section: "
print += f"<br /> Assignment name: {i.name} <br /> Description: {i.description} <br /> Perfect score: {i.max_points} <br /> Passing score: {i.passing_score} <br /> Course/Section: {i.course} <br />"
return HttpResponse(print)
# Create your views here. # Create your views here.
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