feat: update models and respective entries in assignments app

Add passing_score field to Assignments model.
Create new model "Course" and its admin.

Add relationship between Assignment and Course models.
parent 0e34ffd2
from django.contrib import admin from django.contrib import admin
# Register your models here. # Register your models here.
from .models import Assignment from .models import Assignment, Course
class AssignmentAdmin(admin.ModelAdmin): class AssignmentAdmin(admin.ModelAdmin):
model = Assignment model = Assignment
admin.site.register(Assignment, AssignmentAdmin) class CourseAdmin(admin.ModelAdmin):
\ No newline at end of file model = Course
admin.site.register(Assignment, AssignmentAdmin)
admin.site.register(Course, CourseAdmin)
\ No newline at end of file
# Generated by Django 4.0.3 on 2022-03-20 18:24
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Assignment',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=50)),
('description', models.CharField(max_length=200)),
('max_points', models.IntegerField()),
],
),
]
# 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.db import models
from django.core.validators import RegexValidator
# Create your models here. # 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): class Assignment(models.Model):
name = models.CharField(max_length=50) name = models.CharField(max_length=50)
description = models.CharField(max_length=200) description = models.CharField(max_length=200)
max_points = models.IntegerField() max_points = models.IntegerField()
course = models.ForeignKey(
'Course',
on_delete=models.CASCADE,
default=None,
null=True
)
def __str__(self): def __str__(self):
return self.name return self.name
@property
def passing_score(self):
return int(self.max_points*0.6)
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