Commit c4b9ef9e authored by JayCay's avatar JayCay

Could output some review onto page and made classes

parent f0d57241
from django.contrib import admin
# Register your models here.
from django.apps import AppConfig
class ReviewsConfig(AppConfig):
name = 'reviews'
# -*- coding: utf-8 -*-
# Generated by Django 1.11.6 on 2017-10-10 04:34
from __future__ import unicode_literals
import django.core.validators
from django.db import migrations, models
import django.db.models.deletion
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)),
],
),
migrations.CreateModel(
name='Review',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('message', models.TextField(max_length=4000)),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(null=True)),
('rating', models.IntegerField(default=5, validators=[django.core.validators.MaxValueValidator(5), django.core.validators.MinValueValidator(0)])),
('prof', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='reviews', to='reviews.Prof')),
],
),
]
from django.db import models
from django.core.validators import MaxValueValidator, MinValueValidator
from django.contrib.auth.models import User
# 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)
updated_at = models.DateTimeField(null = True)
rating = models.IntegerField(
default = 5,
validators = [MaxValueValidator(5), MinValueValidator(0)]
)
prof = models.ForeignKey(Prof, related_name = 'reviews')
def __str__ (self):
return self.message
\ No newline at end of file
from django.test import TestCase
# Create your tests here.
from django.shortcuts import render
from .models import Review
# Create your views here.
def index(request):
reviews = Review.objects.all()
return render(request, 'reviews.html', {'reviews': reviews})
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
{% for review in reviews %}
{{ review.message }}
{% endfor %}
\ 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