#！ -*- coding:utf-8 -*-
from __future__ import unicode_literals

from django.db import models
from django.contrib.auth import authenticate

# Create your models here.

sex_t = (
    (0,u'男'),
    (1,u'女'),
)

em_t = (
    (0,u'讲师'),
    (1,u'校长'),
    (2,u'班主任'),
    (3,u'招聘'),
)

class Employee_t(models.Model):
    type_of_work = models.CharField(max_length=10,unique=True)
    def __unicode__(self):
        return "%s"%(self.type_of_work)
    class Meta:
        verbose_name_plural = u'员工种类'

class School(models.Model):
    name = models.CharField(max_length=30,verbose_name=u'学校名')
    # principal = models.ForeignKey(Employee,verbose_name=u'校长',null=True,blank=True)
    def __unicode__(self):
        return "%s"%(self.name)

    class Meta:
        verbose_name = u'学校'
        verbose_name_plural = u'学校'


class Employee(models.Model):
    name = models.CharField(max_length=30,verbose_name=u'姓名')
    sex = models.IntegerField(choices=sex_t,verbose_name=u'性别')
    phone = models.CharField(max_length=11,verbose_name=u'手机号')
    em_c = models.ManyToManyField(Employee_t,verbose_name=u'职位')
    school = models.ManyToManyField(School)
    def __unicode__(self):
        return "%s"%(self.name)

    class Meta:
        verbose_name = u'员工'
        verbose_name_plural = u'员工'



class Course(models.Model):
    course_name = models.CharField(max_length=30,unique=True,verbose_name=u'课程')
    def __unicode__(self):
        return "%s"%(self.course_name)

    class Meta:
        verbose_name_plural = u'课程'


class Classmate(models.Model):
    class_t = (
        (0,u'面授班'),
        (1,u'网络班'),
    )
    course = models.ForeignKey(Course,verbose_name=u'班级')
    session = models.IntegerField(verbose_name=u'期数')
    class_way = models.IntegerField(choices=class_t,verbose_name=u'授课方式')
    class_num = models.IntegerField(verbose_name=u'班次')
    teacher = models.ForeignKey(Employee,verbose_name=u'讲师')
    school = models.ForeignKey(School,verbose_name=u'校区')
    def __unicode__(self):
        # n = self.session
        return "%s"%(self.course)
    class Meta:
        verbose_name = u'班级'
        verbose_name_plural = u'班级'
        unique_together=('course','session','class_way','class_num','school')




class Student(models.Model):
    status_type = (
        ('done',u'已报名'),
        ('donot',u'未报名'),
        ('wellgo',u'已结业'),
        ('badgo',u'退学')
    )

    qq = models.CharField(max_length=13,verbose_name=u'QQ号')
    phone = models.CharField(max_length=11,verbose_name=u'手机号码')
    classmate = models.ManyToManyField(Classmate)
    # course = models.ManyToManyField(Course)
    name = models.CharField(max_length=20)
    sex = models.IntegerField(choices=sex_t)
    grade = models.IntegerField(null=True,blank=True)
    status = models.CharField(choices=status_type,default='donot',max_length=10)
    def __unicode__(self):
        return "%s:%s"%(self.name,self.qq)

    class Meta:
        verbose_name_plural = u'学生'
        permissions = (
            ('view_student_list',u'查看学生列表'),
        )



class Question(models.Model):
    question_text = models.CharField(max_length=200)
    pub_date = models.DateTimeField('date published')


class Choice(models.Model):
    question = models.ForeignKey(Question, on_delete=models.CASCADE)
    choice_text = models.CharField(max_length=200)
    votes = models.IntegerField(default=0)







