class Professor(AbstractBaseUser): nome = models.CharField(max_length=120) ra = models.IntegerField(unique=True) password = models.TextField() status = models.BooleanField(default=True) email = models.CharField(max_length=80, blank=True, null=True) perfil = models.CharField(max_length=1, blank=True, default='P') celular = models.CharField(max_length=11, blank=True, null=True) USERNAME_FIELD = 'ra' REQUIRED_FIELDS = ['nome', 'email'] def __str__(self): return self.nome + '(' + str(self.ra) + ')' class Meta: managed = False db_table = 'professor'
class Customer(models.Model): first_name = models.CharField(max_length=32) last_name = models.CharField(max_length=32) email = models.EmailField(null=True, blank=True) phone = models.CharField(max_length=32, null=True, blank=True) profile_key = models.CharField(max_length=32, null=True, blank=True) address = models.CharField(max_length=32, null=True, blank=True) rewards_points = models.IntegerField(null=True, blank=True) account_number = models.CharField(max_length=64, blank=True) notes = models.TextField(null=True, blank=True) archived = models.BooleanField(default=False) created = models.DateTimeField(editable=False) city = models.CharField(verbose_name=_('City'), max_length=58, null=True, blank=True) state = models.CharField(verbose_name=_('State'), max_length=2, choices=STATE_CHOICES, null=True, blank=True) zipcode = models.CharField(verbose_name=_('Zip code'), max_length=8, null=True, blank=True) group = models.ForeignKey(CustomerGroup, blank=True, null=True, related_name='taskin_group') def __unicode__(self): return u'%s %s' % (self.first_name, self.last_name) def save(self, *args, **kwargs): """ On save, update timestamps """ if not self.id: self.created = datetime.today() return super(Customer, self).save(*args, **kwargs) def get_full_name(self): return self.first_name + ' ' + self.last_name
class Usuario(AbstractBaseUser): ra = models.IntegerField('RA', unique=True) nome = models.CharField(max_length=120) email = models.CharField(max_length=80) password = models.TextField() status = models.BooleanField('Status', default=True) perfil = models.CharField('Perfil', max_length=1, default='C') # criando qual o campo de identificação do 'USUARIO' USERNAME_FIELD = 'ra' #colocando com campo de inserção obrigatorio no 'BANCO' REQUIRED_FIELDS = [ 'nome', 'email', ] objects = UsuarioManager() # criando a função de apresentação do 'USUARIO' def __str__(self): return self.nome # criando as funcoes de como ira mostra o nome do 'USUARIO' nos Templates # Funções 'OBRIGATORIAS pelo DJANGO def get_full_name(self): return self.nome def get_short_name(self): return self.nome def has_perm(self, perm, obj=None): return True def has_module_perms(self, app_label): return True @property def is_staff(self): return self.perfil == 'C'
class PersonalInformation(models.Model): user = models.OneToOneField(User, related_name='personal_information', on_delete=models.CASCADE) place_birth = models.CharField(max_length=255, null=True, blank=True) birth_date = models.DateField(null=True, blank=True) has_children = models.BooleanField(null=True, blank=True, default=None) number_of_children = models.IntegerField(null=True, blank=True, default=None) gender = models.ForeignKey(Gender, related_name='gender', null=True, blank=True, on_delete=models.CASCADE) marital_status = models.ForeignKey(MaritalStatus, on_delete=models.CASCADE) marital_status_description = models.TextField(null=True, blank=True) height = models.FloatField(null=True, blank=True) weight = models.FloatField(null=True, blank=True) created_at = models.DateTimeField(auto_now_add=True, null=True) updated_at = models.DateTimeField(auto_now=True, null=True)
class MyUser(AbstractUser): birthday = models.DateField(null=True) random_number = models.IntegerField(default=random.randint(0, 100)) def get_absolute_url(self): return u'/user/%d' % self.id
class Employee(AbstractBaseUser, PermissionsMixin): email = models.EmailField(unique=True, verbose_name=_('Email'), null=False, blank=False) photo = models.ImageField(upload_to='employee_photo/', verbose_name=_('P'), blank=True, default='employee_photo/def.jpg') name = models.CharField(verbose_name=_('Name'), max_length=32) address = models.CharField(verbose_name=_('Address'), max_length=32, null=True, blank=True) address2 = models.CharField(verbose_name=_("Address2"), null=True, blank=True, max_length=32) city = models.CharField(verbose_name=_('City'), max_length=32, null=True, blank=True) state = models.CharField(verbose_name=_('State'), max_length=2, choices=STATE_CHOICES, null=True, blank=True) zipcode = models.CharField(verbose_name=_('Zip code'), max_length=8, null=True, blank=True) phone = models.CharField(verbose_name=_('Phone'), max_length=60, null=True, blank=True) pin = models.IntegerField(verbose_name=_('Pin'), unique=True, null=True) role = models.IntegerField(verbose_name=_('Role'), choices=ROLES) vein_string = models.TextField(blank=True, verbose_name=_('Vein String')) hourly_rate = models.DecimalField(blank=True, null=True, verbose_name=_('Hourly Rate'), decimal_places=2, max_digits=5) archived = models.BooleanField(default=False) store = models.ForeignKey(Store, verbose_name='Store', blank=True, null=True) USERNAME_FIELD = 'email' is_staff = models.BooleanField(default=False) is_active = models.BooleanField(default=False) created = models.DateTimeField(editable=False) objects = EmployeeManager() def __unicode__(self): return u"%s" % self.name def get_full_name(self): return self.name def get_short_name(self): return self.name def check_is_owner(self): return self.role == ROLES[0][0] def return_id(self): return self.id def save(self, *args, **kwargs): ''' On save, update timestamps ''' if self.photo: try: self.photo = resize_image(self.photo, newsize=EMPLOYEE_PHOTO_SIZE) except: logger.exception("Error resizing image for product %s" % self.pk) pass if not self.id: self.created = datetime.today() return super(Employee, self).save(*args, **kwargs)