Commit 5d0c3bca authored by Gab De Jesus's avatar Gab De Jesus

Added base template under academe/templates/base.html

Made a prof app
Can now add profs
parent c9580eb2
......@@ -39,6 +39,7 @@ INSTALLED_APPS = [
'django.contrib.staticfiles',
'reviews',
'profs',
]
MIDDLEWARE = [
......@@ -56,7 +57,9 @@ ROOT_URLCONF = 'academe.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'DIRS': [
'',
],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
......@@ -82,7 +85,6 @@ DATABASES = {
}
}
# Password validation
# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators
......@@ -107,7 +109,7 @@ AUTH_PASSWORD_VALIDATORS = [
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
TIME_ZONE = 'Asia/Manila'
USE_I18N = True
......
......@@ -18,7 +18,10 @@ from django.contrib import admin
from reviews import views as reviews_views
from profs import views as profs_views
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^$', reviews_views.index, name="reviews_index"),
url(r'^profs/', profs_views.index, name="profs_index"),
]
No preview for this file type
from django.contrib import admin
# Register your models here.
from django.apps import AppConfig
class ProfsConfig(AppConfig):
name = 'profs'
from django.forms import ModelForm
from profs.models import Prof
class ProfForm(ModelForm):
class Meta:
model = Prof
fields = ['first_name', 'last_name']
\ No newline at end of file
# -*- coding: utf-8 -*-
# Generated by Django 1.11.5 on 2017-10-24 01:47
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Prof',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('first_name', models.CharField(max_length=20)),
('last_name', models.CharField(max_length=20)),
],
),
]
from django.db import models
# Create your models here.
class Prof(models.Model):
first_name = models.CharField(max_length = 20, unique = False)
last_name = models.CharField(max_length = 20, unique = False)
def __str__ (self):
return self.first_name + self.last_name
\ No newline at end of file
{% extends 'templates/base.html' %}
{% block content %}
<center><h1>Profs</h1></center>
<table style="border: 1px solid black">
<tr>
<th>First Name</th>
<th>Last Name</th>
</tr>
<!-- Create the table rows -->
{% for prof in profs %}
<tr>
<th>{{ prof.first_name }}</th>
<th>{{ prof.last_name }}</th>
</tr>
{% endfor %}
</table>
<!-- Make the form for uploading a new prof -->
<h1>New prof</h1>
<form method="POST">
{% csrf_token %}
{{ prof_form.as_p }}
<button type="submit">Save</button>
</form>
{% endblock %}
\ No newline at end of file
from django.test import TestCase
# Create your tests here.
from django.shortcuts import render, redirect
from django.urls import reverse
from profs.models import Prof
from profs.forms import ProfForm
# Create your views here.
def index(request):
if(request.method=='POST'):
form = ProfForm(request.POST)
if(form.is_valid()):
form.save()
# Return to profs_index using reverse so only need to change url in settings.py
return redirect(reverse('profs_index'))
profs = Prof.objects.all()
return render(request, 'profs/index.html', {'prof_form':ProfForm, 'profs': profs})
[
{
"model": "reviews.prof",
"pk": 1,
"fields": {
"first_name": "Gab",
"last_name": "De Jesus"
}
},
{
"model": "reviews.prof",
"pk": 2,
"fields": {
"first_name": "Jayce",
"last_name": "Ching"
}
},
{
"model": "reviews.prof",
"pk": 3,
"fields": {
"first_name": "Josh",
"last_name": "Castillo"
}
},
{
"model": "reviews.prof",
"pk": 4,
"fields": {
"first_name": "Nate",
"last_name": "Kibanoff"
}
}
]
\ No newline at end of file
from django.forms import ModelForm
from .models import Prof, Review
from reviews.models import Review
class ReviewForm(ModelForm):
class Meta:
......
# -*- coding: utf-8 -*-
# Generated by Django 1.11.5 on 2017-10-24 01:47
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('reviews', '0002_course'),
]
operations = [
migrations.AlterField(
model_name='review',
name='prof',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='reviews', to='profs.Prof'),
),
migrations.DeleteModel(
name='Prof',
),
]
......@@ -2,19 +2,15 @@ from django.db import models
from django.core.validators import MaxValueValidator, MinValueValidator
from django.contrib.auth.models import User
# Import profs
from profs.models import Prof
# Create your models here.
class Course(models.Model):
name = models.CharField(max_length = 15, unique = True)
description = models.CharField(max_length = 100)
class Prof(models.Model):
first_name = models.CharField(max_length = 20, unique = False)
last_name = models.CharField(max_length = 20, unique = False)
def __str__ (self):
return self.first_name + self.last_name
class Review(models.Model):
message = models.TextField(max_length = 4000)
created_at = models.DateTimeField(auto_now_add = True)
......
{% extends 'templates/base.html' %}
{% block content %}
<center><h1>Reviews</h1></center>
<table style="border: 1px solid black">
<tr>
<th>Prof Name</th>
<th>Review</th>
<th>Rating</th>
<th>Created At</th>
<th>Updated At</th>
</tr>
<!-- Create the table rows -->
{% for review in reviews %}
<tr>
<td>{{ review.prof.first_name }} {{ review.prof.last_name }}</td>
<td>{{ review.message }}</td>
<td>{{ review.rating }}</td>
<td>{{ review.created_at }}</td>
<td>{{ review.updated_at }}</td>
</tr>
{% endfor %}
</table>
<!-- Make the form for uploading a new review -->
<h1>New review</h1>
<form method="POST">
{% csrf_token %}
{{ upload_form.as_p }}
<button type="submit">Save</button>
</form>
{% endblock %}
\ No newline at end of file
from django.shortcuts import render
from .models import Review, Prof
from django.shortcuts import render, redirect
from django.urls import reverse
from .models import Review
from profs.models import Prof
from .forms import ReviewForm
# Create your views here.
......@@ -8,9 +10,11 @@ def index(request):
form = ReviewForm(request.POST)
if(form.is_valid()):
form.save()
# Return to reviews index so that no more post on refresh
return redirect(reverse('reviews_index'))
reviews = Review.objects.all()
profs = Prof.objects.all()
upload_form = ReviewForm()
return render(request, 'index.html', {'reviews': reviews, 'upload_form': upload_form, 'profs': profs})
return render(request, 'reviews/index.html', {'reviews': reviews, 'upload_form': upload_form, 'profs': profs})
......@@ -21,33 +21,14 @@
</style>
</head>
<body>
<center><h1>Reviews</h1></center>
<table style="border: 1px solid black">
<tr>
<th>Prof Name</th>
<th>Review</th>
<th>Rating</th>
<th>Created At</th>
<th>Updated At</th>
</tr>
<!-- Create the table rows -->
{% for review in reviews %}
<tr>
<td>{{ review.prof.first_name }} {{ review.prof.last_name }}</td>
<td>{{ review.message }}</td>
<td>{{ review.rating }}</td>
<td>{{ review.created_at }}</td>
<td>{{ review.updated_at }}</td>
</tr>
{% endfor %}
</table>
<!-- Make the form for uploading a new review -->
<h1>New review</h1>
<form method="POST">
{% csrf_token %}
{{ upload_form.as_p }}
<button type="submit">Save</button>
</form>
<h1><center>Academe</center></h1>
<nav>
<ul>
<li><a href="{% url 'reviews_index' %}">Home</a></li>
<li><a href="{% url 'profs_index' %}">Profs</a></li>
</ul>
</nav>
{% block content %}
{% endblock %}
</body>
</html>
\ 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