Commit b93bb5c4 authored by Patricia Isabella Nava's avatar Patricia Isabella Nava

Merge branch 'nava/assignments'

parents 124a5053 9c21583b
from django.contrib import admin
# Register your models here.
from .models import Assignment
from .models import Assignment, Course
class AssignmentAdmin(admin.ModelAdmin):
model = Assignment
class CourseAdmin(admin.ModelAdmin):
model = Course
admin.site.register(Assignment, AssignmentAdmin)
admin.site.register(Course, CourseAdmin)
\ No newline at end of file
# Generated by Django 3.2.12 on 2022-03-30 14:57
import django.core.validators
from django.db import migrations, models
import django.db.models.deletion
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=100)),
('section', models.SlugField(max_length=3, validators=[django.core.validators.RegexValidator('^[a-zA-Z]*$')])),
],
),
migrations.AddField(
model_name='assignment',
name='course',
field=models.ForeignKey(default=None, null=True, on_delete=django.db.models.deletion.CASCADE, to='assignments.course'),
),
]
from pyexpat import model
from django.db import models
from django.core.validators import RegexValidator
# Create your models here.
class Course(models.Model):
course_code = models.CharField(max_length=10)
course_title = models.CharField(max_length=100)
section = models.SlugField(
max_length=3,
validators=[RegexValidator(r'^[a-zA-Z]*$')]
)
def __str__(self):
return self.course_code + " - " + self.course_title
class Assignment(models.Model):
name = models.CharField(max_length=50)
description = models.CharField(max_length=200)
max_points = models.IntegerField()
course = models.ForeignKey(
'Course',
on_delete=models.CASCADE,
default=None,
null=True
)
def __str__(self):
return self.name
@property
def passing_score(self):
return int(self.max_points*0.6)
<!DOCTYPE html>
<html>
<head></head>
<body>
<h1> ASSIGNMENTS: </h1>
{% for assignment in assignment_entries %}
<p>
Assignment Name: {{assignment.name}}<br>
Description: {{assignment.description}}<br>
Perfect Score: {{assignment.max_points}}<br>
Passing Score: {{assignment.passing_score}}<br>
Course/Section: {{assignment.course.course_code}} {{assignment.course.course_title}} | {{assignment.course.section}}
</p>
{% endfor %}
</body>
</html>
from django.http import HttpResponse
from django.template import loader
from .models import Course, Assignment
# Create your views here.
def index(request):
return HttpResponse("This is the Assignments page!")
\ No newline at end of file
assignments = Assignment.objects.all()
template = loader.get_template('assignments/index.html')
context = {
'assignment_entries': assignments
}
return HttpResponse(template.render(context, request))
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