Advertisement
phiron

Classe do projeto

Oct 23rd, 2012
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.92 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. from django.db import models
  3. from django.db.models import Q
  4. from datetime import datetime
  5.  
  6. class Professor(models.Model):
  7.     nome = models.CharField(max_length = 100, unique = True)
  8.     telefone = models.CharField(max_length = 40)
  9.     email = models.EmailField()
  10.     departamento = models.ForeignKey('Departamento')
  11.     cargo = models.ManyToManyField('Cargo')
  12.     curso = models.ManyToManyField('Curso', related_name = 'curso', through = "Matricula")
  13.     data_cadastro_curso = models.DateField(null = True, blank = True)
  14.     def __unicode__(self):
  15.         return self.nome
  16.     class Meta:
  17.         ordering = ['nome']
  18.         verbose_name_plural = u'professores'
  19.  
  20. class Curso(models.Model):
  21.     nome = models.CharField(max_length = 100)
  22.     data = models.DateTimeField()
  23.     professor = models.CharField(max_length = 100, null = True, blank = True)
  24.     requisitos = models.ManyToManyField('Curso', blank = True, null = True, related_name = 'requisitos_do_curso')
  25.     def __unicode__(self):
  26.         return u'%s - %s' % (self.nome, self.data)
  27.  
  28. class Matricula(models.Model):
  29.     professor = models.ForeignKey(Professor)
  30.     #curso = models.ForeignKey(Curso, limit_choices_to = (Q(data__gte = datetime.now())))
  31.     curso = models.ForeignKey(Curso)
  32.     concluido = models.BooleanField(blank = True, default = False)
  33.     def __unicode__(self):
  34.         return u" %s no curso %s" % (self.professor.nome, self.curso.nome)
  35.     class Meta:
  36.         db_table = "cadastro_professor_curso"
  37.         verbose_name = u"Matrícula"
  38.  
  39. class Departamento(models.Model):
  40.     chefe = models.ForeignKey(Professor, related_name = 'chefe_dp')
  41.     nome = models.CharField(max_length = 30)
  42.     obs = models.TextField(blank = True, null = True)
  43.     def __unicode__(self):
  44.         return self.nome
  45.  
  46. class Cargo(models.Model):
  47.     nome = models.CharField(max_length = 100)
  48.     def __unicode__(self):
  49.         return self.nome
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement