You've already posted the same question: https://groups.google.com/g/django-users/c/f7ZH2pcZp0s
On Wednesday, 20 April 2022 at 16:44:19 UTC+2 [email protected] wrote: > I have a model Staff and LeaveReportStaff, I wanted to get leave_balance > between Total_Leave_Days and leave_days. I already used Foreignkey for > staff but I'm not sure if it is right to use Foreignkey again. > > Please advise the best way forward. > > class Staff(models.Model): > Total_Leave_Days = models.PositiveIntegerField(default=0) > course = models.ForeignKey(Course, on_delete=models.DO_NOTHING, > null=True, blank=False) > admin = models.OneToOneField(CustomUser, on_delete=models.CASCADE) > > > class LeaveReportStaff(models.Model): > staff = models.ForeignKey(Staff, on_delete=models.CASCADE) > start_date = models.DateField() > end_date = models.DateField() > leave_type = models.CharField(choices=LEAVE_TYPE, max_length=25, > null=True, blank=False) > > @property > def leave_days(self): > return (self.end_date - self.start_date).days > > @property > def leave_balance(self): > return (self.Total_Leave_Days - self.leave_days) > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/498d046c-84e9-4ee6-914c-14a373c50625n%40googlegroups.com.

