Commit a0f9a89a authored by Jeremy Factor's avatar Jeremy Factor

created a migration for course model

parent c07c16ae
......@@ -2,6 +2,7 @@ from django.contrib import admin
# Register your models here.
from .models import Assignment
from .models import Course
class AssignmentAdmin(admin.ModelAdmin):
model = Assignment
......@@ -10,4 +11,12 @@ class AssignmentAdmin(admin.ModelAdmin):
list_display = ('name', 'description',)
list_filter = ('name','max_points',)
class CourseAdmin(admin.ModelAdmin):
model = Course
search_fields = ('course_code',)
list_display = ('course_code', 'course_title', 'section',)
list_filter = ('course_title', 'section',)
admin.site.register(Assignment, AssignmentAdmin)
admin.site.register(Course, CourseAdmin)
\ No newline at end of file
# Generated by Django 3.2.12 on 2022-04-07 22:59
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('assignments', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='assignment',
name='passing_score',
field=models.IntegerField(default=0),
),
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)),
('assignment', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='assignments.assignment')),
],
),
]
......@@ -6,5 +6,17 @@ class Assignment(models.Model):
description = models.CharField(max_length = 500)
max_points = models.IntegerField(default = 0)
passing_score = models.IntegerField(default = 0)
def __str__(self):
return self.name
class Course(models.Model):
course_code = models.CharField(max_length = 10)
course_title = models.CharField(max_length = 50)
section = models.CharField(max_length = 3)
assignment = models.ForeignKey(Assignment, on_delete=models.CASCADE)
def __str__(self):
return self.course_code
\ No newline at end of file
from django.http import HttpResponse
from assignments.models import Assignment
from assignments.models import Course
# Create your views here.
def index(request):
return HttpResponse("This is the Assignments Page!")
\ No newline at end of file
assignment_objects = Assignment.objects.all()
course_objects = Course.objects.all()
response = "ASSIGNMENTS:<br>"
for assignment in assignment_objects:
response = (response + f"<br> Assignment Name: {assignment.name} <br>"
+ f"Description: {assignment.description} <br>"
+ f"Perfect Score: {assignment.max_points} <br>"
+ f"Passing Score: {assignment.passing_score} <br>")
for course in course_objects:
if(course.assignment.name==assignment.name):
response = (response + "Course/Section: " +
f"{course.course_code} {course.course_title} {course.section} <br>")
return HttpResponse(response)
\ No newline at end of file
......@@ -7,8 +7,8 @@ class WidgetUser(models.Model):
middle_name = models.CharField(max_length=50)
last_name = models.CharField(max_length=50)
id_num = models.CharField(max_length=7)
email = models.EmailField(max_length=100)
id_num = models.CharField(max_length=7, default=0)
email = models.EmailField(max_length=100, null=True)
def __str__(self):
return self.last_name
......@@ -17,7 +17,7 @@ class WidgetUser(models.Model):
class Department(models.Model):
#Two Parameters (Model to which the Association is being made, process that you want to be done when a particular model is deleted)
user = models.ForeignKey(WidgetUser, on_delete=models.CASCADE)
user = models.ForeignKey(WidgetUser, on_delete=models.CASCADE,)
dept_name = models.CharField(max_length=50)
home_unit = models.CharField(max_length=50)
......
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