Added Course model, updated Assignment model and views'

parent fe674a9e
from django.contrib import admin
from .models import Assignment
from .models import Assignment, Course
# Register your models here.
class AssignmentAdmin(admin.ModelAdmin):
model = Assignment
class CourseAdmin(admin.ModelAdmin):
model = Course
admin.site.register(Assignment, AssignmentAdmin)
admin.site.register(Course, CourseAdmin)
\ No newline at end of file
# Generated by Django 4.0.3 on 2022-04-04 09:04
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('assignments', '0001_initial'),
]
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)),
],
),
]
# Generated by Django 4.0.3 on 2022-04-04 09:08
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('assignments', '0002_course'),
]
operations = [
migrations.AddField(
model_name='assignment',
name='course',
field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, to='assignments.course'),
preserve_default=False,
),
]
from django.db import models
# 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 '{} {} {}'.format(self.course_code, self.course_title, self.section)
class Assignment(models.Model):
name = models.CharField(max_length=50)
description = models.CharField(max_length=500)
max_points = models.IntegerField()
course = models.ForeignKey(Course, on_delete = models.CASCADE)
@property
def passing_score(self):
return self.max_points * 0.60
def __str__(self):
assignment = '<br>Assignment Name: {}'.format(self.name)
assignment += '<br>Description: {}'.format(self.description)
assignment += '<br>Perfect Score: {}'.format(self.max_points)
assignment += '<br>Passing Score: {}'.format(self.passing_score)
assignment += '<br>Course/Section: {}<br>'.format(self.course.__str__())
return assignment
\ No newline at end of file
from django.shortcuts import render
from django.http import HttpResponse
from .models import Assignment
# Create your views here.
def index(request):
return HttpResponse("This is the Assignments page!")
\ No newline at end of file
def assignment_list():
final_list = ''
for a in range(len(Assignment.objects.all())):
final_list += '{}'.format(Assignment.objects.get(pk=a+1).__str__())
return final_list
html = f'''
<html>
<body>
<header><h1>ASSIGNMENTS:</h1><header>
<main>
<p>{assignment_list()}</p>
</main>
</body>
</html>
'''
return HttpResponse(html)
\ No newline at end of file
No preview for this file type
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