设计数据库
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models
from django.contrib.auth.models import User
# Create your models here.
class Myclass(models.Model):
name = models.CharField(max_length=100)
def __unicode__(self):
return self.name
class WorkRoom(models.Model):
name = models.CharField(max_length=200)
def __unicode__(self):
return self.name
class Student(models.Model):
name = models.CharField(max_length=200, default=0)
student_class = models.ForeignKey(
Myclass,
on_delete=models.CASCADE,
verbose_name="student class",
)
work_room = models.ForeignKey(
WorkRoom,
default=0,
on_delete=models.CASCADE,
verbose_name="work room",
)
user = models.OneToOneField(
User,
on_delete=models.CASCADE,
verbose_name="login user",
default=0,
)
def __unicode__(self):
return str(self.id) + " " + self.user.username + " " \
+ self.student_class.name + " "
class Teacher(models.Model):
name = models.CharField(max_length=200, default=0)
staff_no = models.CharField(max_length=20)
STAFF_ROOM_CHOICES = (
('network', '计算机网络'),
('information', '信息技术'),
('software', '计算软件'),
('application', '计算机应用'),
('iot', '物联网应用'),
)
work_room = models.ForeignKey(
WorkRoom,
default=0,
on_delete=models.CASCADE,
verbose_name="work room",
)
staff_room = models.CharField(
max_length=20,
choices=STAFF_ROOM_CHOICES,
default='network',
)
user = models.OneToOneField(
User,
on_delete=models.CASCADE,
verbose_name="login user",
default=0,
)
def __unicode__(self):
return self.name
class Task(models.Model):
title = models.CharField(max_length=200)
content = models.TextField()
file = models.FileField(upload_to='uploads/%Y/%m/%d')
creator = models.ForeignKey(
Teacher, default=0
)
member = models.ManyToManyField(
Student,
)
create_date = models.DateTimeField(auto_now_add=True)
update_date = models.DateTimeField(auto_now=True)
deadline = models.CharField(max_length=200)
def __unicode__(self):
return self.title
class TaskReport(models.Model):
student = models.ForeignKey(Student, default=0)
task = models.ForeignKey(Task, default=0)
content = models.BinaryField()
file = models.FileField(upload_to='uploads/%Y/%m/%d')
create_date = models.DateTimeField(auto_now=False)
GRADE_CHOICES = (
('A', 'EXCELLENT'),
('B', 'GOOD'),
('C', 'NOT BAD'),
('D', 'BAD'),
)
grade = models.CharField(
max_length=1,
choices=GRADE_CHOICES,
default='B',
)
teachers_comment = models.BinaryField()
create_date = models.DateTimeField(auto_now=False)
写模板,登陆页面,教师登陆成功的首页,创建任务页面,显示任务详情页面