SHARE
TWEET

Untitled

a guest Apr 21st, 2017 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from django.db import models
  2. from django.contrib.auth.models import User
  3.  
  4.  
  5.  
  6.  
  7. class LeaveRecordDetail(models.Model):
  8.     employee = models.ForeignKey(User, related_name='employee', on_delete=models.CASCADE)
  9.     reporting_manager = models.ForeignKey(User, related_name='reporting_manager' ,on_delete=models.CASCADE)
  10.     sick_leaves = models.IntegerField(default=14)
  11.     earned_leaves = models.IntegerField(default=14)
  12.     personal_leaves = models.IntegerField(default=14)
  13.  
  14.     def __str__(self):
  15.         return str(self.employee) + " " + str(self.reporting_manager)
  16.  
  17.     class Meta:
  18.         db_table = 'LeaveRecord'
  19.  
  20.  
  21.  
  22. class LeaveApplication(models.Model):
  23.  
  24.     TYPES_OF_LEAVES = (
  25.         ('SL', 'SickLeave'),
  26.         ('EL', 'EarnedLeave'),
  27.         ('PL', 'PersonalLeave')
  28.     )
  29.  
  30.     LEAVE_STATUS = (
  31.         ('A', 'Approved'),
  32.         ('R', 'Rejected')
  33.     )
  34.  
  35.     leave_id = models.AutoField(primary_key=True)
  36.     applicant = models.ForeignKey(User, related_name='applicant', on_delete=models.CASCADE)
  37.     approver = models.ForeignKey(User, related_name='approver', on_delete=models.CASCADE)
  38.     created_on = models.DateTimeField(auto_now_add=True)
  39.     responded_on = models.DateTimeField(auto_now=True, null=True)
  40.     leave_type = models.CharField(max_length=2, choices=TYPES_OF_LEAVES)
  41.     number_of_days= models.IntegerField()
  42.     from_date = models.DateField()
  43.     to_date = models.DateField()
  44.     leave_status = models.CharField(max_length=1, choices=LEAVE_STATUS, default='R')
  45.     additional_message = models.TextField(max_length=200)
  46.  
  47.     def __str__(self):
  48.         return self.leave_status
  49.  
  50.     class Meta:
  51.         db_table = 'LeaveApplication'
  52.  
  53.     def save(self, force_insert=False, force_update=False, using=None,
  54.              update_fields=None):
  55.         a = LeaveRecordDetail.objects.get(employee = self.applicant)
  56.         if self.applicant == a.employee and self.approver == a.reporting_manager:
  57.             super(LeaveApplication,self).save()
  58.         else:
  59.             raise Exception
RAW Paste Data
Pastebin PRO Summer Special!
Get 40% OFF on Pastebin PRO accounts!
Top