from django.db import models
# 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)

    def __str__(self):
        return "%s | %s - %s" % (self.course_code, self.course_title, self.section)

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)
    course = models.ForeignKey(Course, on_delete=models.CASCADE, default=1)
    assignment_image = models.ImageField(null = True, blank = True, upload_to = "assignments/")

    def __str__(self):
        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)
    
    def get_absolute_url(self):
        return u'%d/details' % self.pk