Commit d575aa7e authored by Caryn Lopez-Go's avatar Caryn Lopez-Go

initial Assignments commit

parent db2ef254
from django.contrib import admin
from .models import Assignment, Course
# Register your models here.
class AssignmentInLine(admin.TabularInline):
model = Assignment
class CourseAdmin(admin.ModelAdmin):
model = Course
list_display = ('code', 'title', 'section')
search_fields = ('code', 'title', 'section')
inlines = [AssignmentInLine]
class AssignmentAdmin(admin.ModelAdmin):
list_display = ('name', 'description', 'course', 'perfect_score', 'passing_score')
def get_name(self, obj):
return obj.assignment.name
get_name.short_description = 'name'
admin.site.register(Assignment, AssignmentAdmin)
admin.site.register(Course, CourseAdmin)
from django.apps import AppConfig
class AssignmentsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'Assignments'
from django.db import models
# Create your models here.
class Course(models.Model):
code = models.CharField(max_length=10)
title = models.CharField(max_length=50)
section = models.CharField(max_length=3)
def __str__(self):
return self.code
class Assignment(models.Model):
name = models.CharField(max_length=50)
description = models.TextField(max_length=500)
course = models.ForeignKey(Course, on_delete=models.CASCADE)
perfect_score = models.PositiveIntegerField(default=0)
passing_score = models.PositiveIntegerField(default=perfect_score*.6)
def __str__(self):
return self.name
\ No newline at end of file
from django.test import TestCase
# Create your tests here.
from django.http import HttpResponse
from .models import Assignment, Course
# Create your views here.
def assignments(request):
homeworks = Assignment.objects.all()
display = 'Widget\'s Assignments Page<br><br>'
for homework in homeworks:
assignment_name = homework.name
assignment_description = homework.description
assignment_perfect_score = homework.perfect_score
assignment_passing_score = homework.passing_score
course_code = homework.course.code
course_title = homework.course.title
course_section = homework.course.section
display += 'Assignment Name: ' + assignment_name + '<br>'
display += 'Description: ' + assignment_description + '<br>'
display += 'Perfect Score: ' + assignment_perfect_score + '<br>'
display += 'Passing Score: ' + assignment_passing_score + '<br>'
display += 'Course/Section: ' + course_code + ' ' + course_title + '-' + course_section + '<br><br>'
return HttpResponse(display)
\ 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