Commit 72d001e7 authored by Bianca Aguilar's avatar Bianca Aguilar

Updating branch since homepage's models were updated

parents af97df63 3a9d9ca2
...@@ -9,6 +9,10 @@ ...@@ -9,6 +9,10 @@
+ Assignments (Lab 1) + Assignments (Lab 1)
+ Assignments Models (Lab 2) + Assignments Models (Lab 2)
+ Homepage Models (Lab 2) + Homepage Models (Lab 2)
+ Assignments Models (Midterm)
+ Assignments View (Midterm)
+ Homepage Models (Midterm)
+ Homepage View (Midterm)
**Nicolas Reichert:** **Nicolas Reichert:**
+ Announcements Models (Lab 2) + Announcements Models (Lab 2)
......
from django.contrib import admin from django.contrib import admin
from .models import Assignment from .models import Assignment, Course
# Register your models here. # Register your models here.
class AssignmentAdmin(admin.ModelAdmin): class AssignmentAdmin(admin.ModelAdmin):
model = Assignment model = Assignment
class CourseAdmin(admin.ModelAdmin):
model = Course
admin.site.register(Assignment, AssignmentAdmin) admin.site.register(Assignment, AssignmentAdmin)
admin.site.register(Course, CourseAdmin)
\ No newline at end of file
# Generated by Django 4.0.3 on 2022-04-04 09:04
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('assignments', '0001_initial'),
]
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)),
],
),
]
# Generated by Django 4.0.3 on 2022-04-04 09:08
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('assignments', '0002_course'),
]
operations = [
migrations.AddField(
model_name='assignment',
name='course',
field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, to='assignments.course'),
preserve_default=False,
),
]
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)
@property
def course_info(self):
return '{} {} {}'.format(self.course_code, self.course_title, self.section)
class Assignment(models.Model): class Assignment(models.Model):
name = models.CharField(max_length=50) name = models.CharField(max_length=50)
description = models.CharField(max_length=500) description = models.CharField(max_length=500)
max_points = models.IntegerField() max_points = models.IntegerField()
course = models.ForeignKey(Course, on_delete = models.CASCADE)
@property
def passing_score(self):
return self.max_points * 0.60
@property
def assignment_info(self):
assignment = '<br>Assignment Name: {}'.format(self.name)
assignment += '<br>Description: {}'.format(self.description)
assignment += '<br>Perfect Score: {}'.format(self.max_points)
assignment += '<br>Passing Score: {}'.format(self.passing_score)
assignment += '<br>Course/Section: {}<br>'.format(self.course.course_info)
return assignment
\ No newline at end of file
from django.shortcuts import render from django.shortcuts import render
from django.http import HttpResponse from django.http import HttpResponse
from .models import Assignment
# Create your views here. # Create your views here.
def index(request): def index(request):
return HttpResponse("This is the Assignments page!") def assignment_list():
\ No newline at end of file final_list = ''
for a in range(len(Assignment.objects.all())):
final_list += '{}'.format(Assignment.objects.get(pk=a+1).assignment_info)
return final_list
html = f'''
<html>
<body>
<header><h1>ASSIGNMENTS:</h1><header>
<main>
<p>{assignment_list()}</p>
</main>
</body>
</html>
'''
return HttpResponse(html)
\ No newline at end of file
from django.contrib import admin from django.contrib import admin
from .models import WidgetUser from .models import WidgetUser, Department
# Register your models here. # Register your models here.
class WidgetUserAdmin(admin.ModelAdmin): class WidgetUserAdmin(admin.ModelAdmin):
model = WidgetUser model = WidgetUser
class DepartmentAdmin(admin.ModelAdmin):
model = Department
admin.site.register(WidgetUser, WidgetUserAdmin) admin.site.register(WidgetUser, WidgetUserAdmin)
admin.site.register(Department, DepartmentAdmin)
\ No newline at end of file
# Generated by Django 4.0.3 on 2022-04-04 12:43
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('homepage', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='Department',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('dept_name', models.CharField(max_length=50)),
('home_unit', models.CharField(max_length=50)),
],
),
migrations.AddField(
model_name='widgetuser',
name='email',
field=models.EmailField(default=1, max_length=254),
preserve_default=False,
),
migrations.AddField(
model_name='widgetuser',
name='id_num',
field=models.CharField(default=1, max_length=7),
preserve_default=False,
),
]
# Generated by Django 4.0.3 on 2022-04-04 12:47
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('homepage', '0002_department_widgetuser_email_widgetuser_id_num'),
]
operations = [
migrations.AddField(
model_name='widgetuser',
name='department',
field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, to='homepage.department'),
preserve_default=False,
),
]
from django.db import models from django.db import models
# Create your models here. # Create your models here.
class Department(models.Model):
dept_name = models.CharField(max_length=50)
home_unit = models.CharField(max_length=50)
@property
def dept_info(self):
return '{}, {}'.format(self.dept_name, self.home_unit)
class WidgetUser(models.Model): class WidgetUser(models.Model):
first_name = models.CharField(max_length=50) first_name = models.CharField(max_length=50)
middle_name = models.CharField(max_length=50) middle_name = models.CharField(max_length=50)
last_name = models.CharField(max_length=50) last_name = models.CharField(max_length=50)
id_num = models.CharField(max_length=7)
email = models.EmailField()
department = models.ForeignKey(Department, on_delete = models.CASCADE)
@property
def full_name(self):
return '{}, {} {}'.format(self.last_name, self.first_name, self.middle_name)
@property
def user_info(self):
return '<br>{}: {}, {}, {}'.format(self.full_name, self.id_num, self.email, self.department.dept_info)
\ No newline at end of file
from django.http import HttpResponse from django.http import HttpResponse
from .models import WidgetUser
def index(request): def index(request):
return HttpResponse('Welcome to Widget!') def user_list():
final_list = ''
for u in range(len(WidgetUser.objects.all())):
final_list += '{}'.format(WidgetUser.objects.get(pk=u+1).user_info)
return final_list
html = f'''
<html>
<body>
<header><h1>WIDGET USERS:</h1><header>
<main>
<p>{user_list()}</p>
</main>
</body>
</html>
'''
return HttpResponse(html)
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