Commit 3826707d authored by Albert Gagalac's avatar Albert Gagalac

Added model-Course and corresponding admin panel

parent 65da053d
...@@ -2,9 +2,13 @@ from django.contrib import admin ...@@ -2,9 +2,13 @@ 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.1.7 on 2023-03-04 14:49
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="Assignment",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("name", models.CharField(default="", max_length=50)),
("description", models.TextField(default="", max_length=700)),
("perfect_score", models.PositiveIntegerField(default=0)),
],
),
migrations.CreateModel(
name="Course",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("code", models.CharField(default="", max_length=10)),
("title", models.CharField(default="", max_length=50)),
(
"section",
models.CharField(
default="",
max_length=3,
unique=True,
validators=[
django.core.validators.RegexValidator(
"r^[a-zA-Z]*$", "Only letters are allowed"
)
],
),
),
],
),
migrations.DeleteModel(
name="Assignments",
),
migrations.AddField(
model_name="assignment",
name="course",
field=models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE, to="assignments.course"
),
),
]
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):
code = models.CharField(default="", max_length=10)
title = models.CharField(default="", max_length=50)
section = models.CharField(
default="",max_length=3,
unique=True,
validators=[RegexValidator(r'^[a-zA-Z]*$',
message='Only letters are allowed')])
def __str__(self):
return "%s %s" % (self.code, self.section)
class Assignment(models.Model): class Assignment(models.Model):
name = models.CharField(default="", max_length=50) name = models.CharField(default="", max_length=50)
description = models.TextField(default="", max_length=700) description = models.TextField(default="", max_length=700)
course = models.CharField(default="", max_length=50) course = models.ForeignKey(Course, on_delete=models.CASCADE)
perfect_score = models.PositiveIntegerField(default=0) perfect_score = models.PositiveIntegerField(default=0)
def __str__(self): def __str__(self):
...@@ -14,7 +28,4 @@ class Assignment(models.Model): ...@@ -14,7 +28,4 @@ class Assignment(models.Model):
@property @property
def pass_score(self): def pass_score(self):
passing_score = self.perfect_score * (60/100) passing_score = self.perfect_score * (60/100)
return passing_score return passing_score
\ 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