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 ...@@ -2,6 +2,7 @@ from django.contrib import admin
# Register your models here. # Register your models here.
from .models import Assignment from .models import Assignment
from .models import Course
class AssignmentAdmin(admin.ModelAdmin): class AssignmentAdmin(admin.ModelAdmin):
model = Assignment model = Assignment
...@@ -10,4 +11,12 @@ class AssignmentAdmin(admin.ModelAdmin): ...@@ -10,4 +11,12 @@ class AssignmentAdmin(admin.ModelAdmin):
list_display = ('name', 'description',) list_display = ('name', 'description',)
list_filter = ('name','max_points',) 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(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): ...@@ -6,5 +6,17 @@ class Assignment(models.Model):
description = models.CharField(max_length = 500) description = models.CharField(max_length = 500)
max_points = models.IntegerField(default = 0) max_points = models.IntegerField(default = 0)
passing_score = models.IntegerField(default = 0)
def __str__(self): def __str__(self):
return self.name 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 django.http import HttpResponse
from assignments.models import Assignment
from assignments.models import Course
# Create your views here. # Create your views here.
def index(request): def index(request):
return HttpResponse("This is the Assignments Page!") assignment_objects = Assignment.objects.all()
\ No newline at end of file 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): ...@@ -7,8 +7,8 @@ class WidgetUser(models.Model):
middle_name = models.CharField(max_length=50) middle_name = models.CharField(max_length=50)
last_name = models.CharField(max_length=50) last_name = models.CharField(max_length=50)
id_num = models.CharField(max_length=7) id_num = models.CharField(max_length=7, default=0)
email = models.EmailField(max_length=100) email = models.EmailField(max_length=100, null=True)
def __str__(self): def __str__(self):
return self.last_name return self.last_name
...@@ -17,7 +17,7 @@ class WidgetUser(models.Model): ...@@ -17,7 +17,7 @@ class WidgetUser(models.Model):
class Department(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) #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) dept_name = models.CharField(max_length=50)
home_unit = 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