Commit acf19b8b authored by Ciella's avatar Ciella

Created models for Assignments app and migrated them

parent 68c2af57
# Generated by Django 4.1.7 on 2023-03-05 15:36
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Course',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('code', models.CharField(max_length=10)),
('title', models.CharField(max_length=255)),
('section', models.CharField(max_length=3)),
],
),
migrations.CreateModel(
name='Assignment',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=255)),
('description', models.TextField()),
('perfect_score', models.IntegerField()),
('passing_score', models.IntegerField(editable=False)),
('course', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='assignments.course')),
],
),
]
from django.db import models from django.db import models
# Create your models here. # Create your models here.
class Course(models.Model):
code = models.CharField(max_length=10)
title = models.CharField(max_length=255)
section = models.CharField(max_length=3)
def __str__(self):
return '{} {}'.format(self.code, self.section)
class Assignment(models.Model):
name = models.CharField(max_length=255)
description = models.TextField()
course = models.ForeignKey(Course, on_delete=models.CASCADE)
perfect_score = models.IntegerField()
passing_score = models.IntegerField(editable=False)
def save(self, *args, **kwargs):
self.passing_score = int(self.perfect_score*0.6)
super(Assignment, self).save(*args, **kwargs)
def __str__(self):
return '{} {}: {}'.format(self.course.code, self.course.section, self.name)
\ No newline at end of file
from django.urls import path
from .views import index
urlpatterns = [
path('', index, name='index'),
]
app_name = 'assignments'
\ No newline at end of file
from django.shortcuts import render from django.shortcuts import render
from django.http import HttpResponse
# Create your views here. # Create your views here.
\ No newline at end of file def index(request):
return HttpResponse('Assignments owo')
\ 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