Commit 09b927b6 authored by Rajo Christian Cadorna's avatar Rajo Christian Cadorna

Added Courses to Assignments app, Linked Courses to Assignments, Added Assignment html template

parents a1e8b1cf dace8258
from django.contrib import admin from django.contrib import admin
# Register your models here. # Register your models here.
from .models import Post from .models import Post, Reply
admin.site.register(Post) admin.site.register(Post)
admin.site.register(Reply)
\ No newline at end of file
# Generated by Django 4.0.3 on 2022-04-04 14:20
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('homepage', '0002_widgetuser_email_widgetuser_id_num_department'),
('Forum', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='post',
name='post_author',
field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, to='homepage.widgetuser'),
),
migrations.CreateModel(
name='Reply',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('reply_body', models.CharField(max_length=50)),
('pub_date', models.DateTimeField(verbose_name='date published')),
('reply_author', models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, to='homepage.widgetuser')),
],
),
]
from django.db import models from django.db import models
from homepage.models import WidgetUser
# Create your models here. # Create your models here.
class Post(models.Model): class Post(models.Model):
post_title = models.CharField(max_length=50) post_title = models.CharField(max_length=50)
post_body = models.CharField(max_length=500) post_body = models.CharField(max_length=500)
pub_date = models.DateTimeField("date published") pub_date = models.DateTimeField("date published")
post_author = models.ForeignKey(WidgetUser, on_delete=models.CASCADE, default=1)
class Reply(models.Model):
reply_body = models.CharField(max_length=50)
pub_date = models.DateTimeField("date published")
reply_author = models.ForeignKey(WidgetUser, on_delete=models.CASCADE, default=1)
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<body>
<h1>~~~Forums Posts~~~</h1>
{% for Post in Post %}
<h4>{{Post.post_title}} by {{Post.post_author.first_name}} {{Post.post_author.last_name}} dated {{Post.pub_date}}</h4>
{{Post.post_body}}
<br></br>
{% endfor %}
<br></br>
{% for Reply in Reply%}
<u>Reply by {{Reply.reply_author.first_name}} {{Reply.reply_author.last_name}} dated {{Reply.pub_date}}:</u> <br>
{{Reply.reply_body}}
<br></br>
{% endfor %}
</body>
</html>
\ No newline at end of file
from django.http import HttpResponse from django.http import HttpResponse
from . models import Post, Reply
from homepage.models import WidgetUser
from django.shortcuts import render
# Create your views here. # Create your views here.
def index(request): def index(request):
return HttpResponse("This is the Forumz!") # create a dictionary to pass
# data to the template
Posts = Post.objects.all()
Replies = Reply.objects.all()
context ={
'Post':Posts,
'Reply':Replies
}
# return response with template and context
return render(request, "view.html", context)
...@@ -2,5 +2,7 @@ from django.contrib import admin ...@@ -2,5 +2,7 @@ from django.contrib import admin
# Register your models here. # Register your models here.
from .models import WidgetUser from .models import WidgetUser
from .models import Department
admin.site.register(WidgetUser) admin.site.register(WidgetUser)
admin.site.register(Department)
# Generated by Django 4.0.3 on 2022-03-30 07:02
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('homepage', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='widgetuser',
name='email',
field=models.EmailField(default=1, max_length=100),
preserve_default=False,
),
migrations.AddField(
model_name='widgetuser',
name='id_num',
field=models.IntegerField(default=1234),
preserve_default=False,
),
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)),
('widgetuser', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='homepage.widgetuser')),
],
),
]
from itertools import chain
from django.db import models from django.db import models
# Create your models here. # Create your models here.
...@@ -5,5 +6,14 @@ class WidgetUser(models.Model): ...@@ -5,5 +6,14 @@ class WidgetUser(models.Model):
first_name = models.CharField(max_length=20) first_name = models.CharField(max_length=20)
middle_name = models.CharField(max_length=10) middle_name = models.CharField(max_length=10)
last_name = models.CharField(max_length=20) last_name = models.CharField(max_length=20)
id_num = models.IntegerField()
email = models.EmailField(max_length=100)
class Department(models.Model):
widgetuser = models.ForeignKey(WidgetUser, on_delete=models.CASCADE)
dept_name = models.CharField(max_length=50)
home_unit = models.CharField(max_length=50)
<!DOCTYPE html>
<html lang="en">
<body>
<h1>WIDGET USERS: </h1>
{% for Depts in Depts %}
<h4>{{Depts.widgetuser.last_name}}, {{Depts.widgetuser.first_name}} {{Depts.widgetuser.middle_name}}: {{Depts.widgetuser.id_num}}, {{Depts.widgetuser.email}}, {{ Depts.dept_name }}, {{ Depts.home_unit }}</h4>
{% endfor %}
</body>
</html>
\ No newline at end of file
from django.http import HttpResponse from django.http import HttpResponse
from . models import WidgetUser
from . models import Department
from django.shortcuts import render
# Create your views here. # Create your views here.
def index(request): def index(request):
return HttpResponse("Welcome to Widget!") widgets = WidgetUser.objects.all()
depts = Department.objects.all()
context ={
'Widgets':widgets,
'Depts':depts
}
return render(request, "view.html", context)
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