Create model Course and add new field passing_score to Assignments app

parent 97516bd1
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
list_display = ('name', 'max_points')
class CourseAdmin(admin.ModelAdmin):
model = Course
list_display = ('course_code', 'course_title')
admin.site.register(Assignment, AssignmentAdmin) admin.site.register(Assignment, AssignmentAdmin)
admin.site.register(Course, CourseAdmin)
# Generated by Django 4.0.3 on 2022-03-31 12:47
from django.db import migrations, models
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=50)),
('section', models.CharField(max_length=3)),
],
),
migrations.AddField(
model_name='assignment',
name='passing_score',
field=models.IntegerField(default=0),
),
]
# Generated by Django 4.0.3 on 2022-03-31 13:03
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('assignments', '0002_course_assignment_passing_score'),
]
operations = [
migrations.AddField(
model_name='assignment',
name='course',
field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, to='assignments.course'),
),
]
from django.db import models from django.db import models
from django.db.models import F
# 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 = 50)
section = models.CharField(max_length = 3)
class Assignment(models.Model): class Assignment(models.Model):
course = models.ForeignKey(Course, on_delete = models.CASCADE, default = 1)
name = models.CharField(max_length = 10) name = models.CharField(max_length = 10)
description = models.CharField(max_length = 50) description = models.CharField(max_length = 50)
max_points = models.IntegerField(default = 0) max_points = models.IntegerField(default = 0)
passing_score = models.IntegerField(default = 0)
def save(self, *args, **kwargs):
self.passing_score = F('max_points')*0.6
super(Assignment, self).save(*args, **kwargs)
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