Added passing_score attribute to assignment model

parent 0dc6ebcc
......@@ -6,6 +6,6 @@ from .models import Assignment
class AssignmentAdmin(admin.ModelAdmin):
model = Assignment
search_fields = ['name', 'description']
list_display = ('name', 'description', 'max_points')
list_display = ('name', 'description', 'passing_score', 'max_points')
admin.site.register(Assignment, AssignmentAdmin)
\ No newline at end of file
# Generated by Django 4.0.3 on 2022-04-02 09:34
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('assignments', '0002_alter_assignment_description'),
]
operations = [
migrations.AddField(
model_name='assignment',
name='passing_score',
field=models.IntegerField(default=0, editable=False),
),
]
......@@ -5,6 +5,12 @@ class Assignment(models.Model):
name = models.CharField(max_length=50)
description = models.TextField(max_length=1500)
max_points = models.IntegerField(default=0)
passing_score = models.IntegerField(default=0, editable=False)
def __str__(self):
return self.name
\ No newline at end of file
return self.name
# Overrides save method to update passing_score value to 60% of max_points
def save(self, *args, **kwargs):
self.passing_score = int(self.max_points*0.6)
return super().save(*args, **kwargs)
\ 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