added the Course model and modified the Assignment model for the foreign key...

added the Course model and modified the Assignment model for the foreign key and passing score. Editted the admin file for viewing in the admin terminal. Editted the views file for viewing in the browser.
parent 7d2c6328
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 CourseAdmin(admin.ModelAdmin):
\ No newline at end of file model = Course
class AssignmentAdmin(admin.ModelAdmin):
model = Assignment
admin.site.register(Assignment)
admin.site.register(Course)
\ No newline at end of file
# Generated by Django 4.0.3 on 2022-04-05 14:55
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=99999)),
('section', models.CharField(max_length=3)),
],
),
]
# Generated by Django 4.0.3 on 2022-04-05 14:55
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(blank=True, default=None, null=True, on_delete=django.db.models.deletion.CASCADE, to='assignments.course'),
),
migrations.AddField(
model_name='assignment',
name='passing_score',
field=models.IntegerField(default=0),
),
]
# Generated by Django 4.0.3 on 2022-04-05 15:19
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('assignments', '0003_assignment_course_assignment_passing_score'),
]
operations = [
migrations.RemoveField(
model_name='assignment',
name='passing_score',
),
]
from multiprocessing.sharedctypes import Value
from django.db import models from django.db import models
DEFAULT_COURSE = 1
# 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=99999)
section = models.CharField(max_length=3)
def __str__(self):
return '{}'.format(self.course_code)
class Assignment(models.Model): class Assignment(models.Model):
name = models.CharField(max_length=100) name = models.CharField(max_length=100)
description = models.CharField(max_length=1000) description = models.CharField(max_length=1000)
max_points = models.IntegerField(default=0) max_points = models.IntegerField(default=0)
course = models.ForeignKey(Course,on_delete=models.CASCADE,default=None,null=True,blank=True)
def passing_score(self):
return int(self.max_points*0.6)
def __str__(self): def __str__(self):
return self.name return '{}'.format(self.name)
\ No newline at end of file
from django.http import HttpResponse from django.http import HttpResponse
from .models import Course, Assignment
assignmentList = Assignment.objects.all()
displayText = "Assignments: "
for i in assignmentList:
eachAssignment = '<br />Assignment Name: {}<br />Description: {}<br />Perfect Score: {}<br />Passing Score: {}<br />Course/Section {} {} {}<br />'.format(i.name, i.description, i.max_points, i.passing_score(), i.course.course_code, i.course.course_title, i.course.section)
displayText += eachAssignment
# Create your views here. # Create your views here.
def index(request): def index(request):
return HttpResponse("This is the Assignments page!") return HttpResponse(displayText)
\ No newline at end of file \ 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