Commit e3adc642 authored by Star Neptune R. Sy's avatar Star Neptune R. Sy

migrated the models

parent 37818654
# Generated by Django 3.2 on 2023-03-05 06:23
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Course',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('course_code', models.CharField(default='', max_length=50, unique=True)),
('course_title', models.CharField(default='', max_length=50, unique=True)),
],
),
migrations.CreateModel(
name='Assignment',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('assignment_name', models.CharField(default='', max_length=50, unique=True)),
('description', models.TextField(default='')),
('perfect_score', models.IntegerField(default=0)),
('passing_score', models.IntegerField(default=0)),
('section', models.CharField(max_length=16, unique=True)),
('course', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='subject', to='assignments.course')),
],
),
]
...@@ -2,20 +2,24 @@ from django.db import models ...@@ -2,20 +2,24 @@ from django.db import models
class Course(models.Model): class Course(models.Model):
course_code = models.CharField(unique=True, default="") course_code = models.CharField(unique=True, default="", max_length=50,)
course_title = models.CharField(unique=True, default="") course_title = models.CharField(unique=True, default="", max_length=50,)
def __str__(self):
return '{} {}-'.format(self.course_code, self.course_title,)
class Assignment(models.Model): class Assignment(models.Model):
assignment_name = models.CharField(unique=True, default="") assignment_name = models.CharField(unique=True, default="", max_length=50,)
description = models.TextField(default="") description = models.TextField(default="")
perfect_score = models.IntegerField() perfect_score = models.IntegerField(default=0)
passing_score = models.IntegerField() passing_score = models.IntegerField(default=0)
section = models.CharField(unique=True) section = models.CharField(unique=True, max_length=16,)
course = models.ForeignKey( course = models.ForeignKey(
Course, Course,
on_delete=models.CASCADE, on_delete=models.CASCADE,
related_name='subject' related_name='subject'
) )
from django.shortcuts import render from django.shortcuts import render
from django.http import HttpResponse
# Create your views here. from .models import Assignment
def index(request):
head = "<h1 style='border-bottom:4px solid lightgray;\
padding-bottom:30px;\
font-size:500%;'>\
Welcome to Widget!\
</h1>"
body = "<h2>WIDGET USERS:</h2>"
for subject in Assignment.objects.all():
body += "<p style='border: 2px solid gray;\
border-radius:5px;\
padding:20px 30px;'>\
Assignment Name: "+subject.assignment_name+" <br>\
Description: "+subject.description+" <br>\
Perfect Score: "+str(subject.perfect_score)+" <br>\
Passing Score: "+str(subject.passing_score)+" <br>\
Course/Section: "+str(subject.course)+str(subject.section)+" <br>\
</p>"
return_string = "<html>\
<body style = 'font-family:helvetica;\
padding:30px;'>\
{}{}\
</body></html>".format(head, body)
return HttpResponse(return_string)
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