Added Course model in assignments app

parent 9bdd23fa
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 CourseAdmin(admin.ModelAdmin):
model = Course
search_fields = ['course_code', 'course_title', 'section']
list_display = ('course_code', 'course_title', 'section')
class AssignmentAdmin(admin.ModelAdmin): class AssignmentAdmin(admin.ModelAdmin):
model = Assignment model = Assignment
search_fields = ['name', 'description'] search_fields = ['name', 'description', 'course']
list_display = ('name', 'description', 'passing_score', 'max_points') list_display = ('name', 'description', 'passing_score', 'max_points', 'course')
admin.site.register(Course, CourseAdmin)
admin.site.register(Assignment, AssignmentAdmin) admin.site.register(Assignment, AssignmentAdmin)
\ No newline at end of file
# Generated by Django 4.0.3 on 2022-04-02 10:51
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('assignments', '0003_assignment_passing_score'),
]
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='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
# 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)
def __str__(self):
return self.course_code
class Assignment(models.Model): class Assignment(models.Model):
name = models.CharField(max_length=50) name = models.CharField(max_length=50)
description = models.TextField(max_length=1500) description = models.TextField(max_length=1500)
max_points = models.IntegerField(default=0) max_points = models.IntegerField(default=0)
passing_score = models.IntegerField(default=0, editable=False) passing_score = models.IntegerField(default=0, editable=False)
course = models.ForeignKey(Course, on_delete=models.CASCADE, default=1)
def __str__(self): def __str__(self):
return self.name return self.name
......
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