models.py
from django.db import models
class Leave(models.Model):
...
from_date = models.DateField()
to_date = models.DateField()
def __str__(self):
return self.name
The above are the two date fields which are defined in my models.py.
views.py
from django.shortcuts import render, render_to_response
from .forms import LeaveRequestForm
from django.shortcuts import
from .models import Leave
...
def get_days(request):
data = Leave.objects.all()
for x in data :
if x.employee_ID == request.user.username:
d1 = x.from_date
d2 = x.to_date
days = d2 - d1
return render(request,"status.html", days)
The above code is my trial on getting the number of days.
Here, my model is Leave
and my form is LeaveRequestForm
. In my HTML file to get the number of days I use {{ from_date|timesince:to_date }}
, this works but i want to deduct this number of days from a number.
base : I'm working on a leave-management project. If a user asks a leave for 5days and he is eligible for 10days. His balance leaves should be equal to 5.
How do I achieve this with the views?