Answer the question
In order to leave comments, you need to log in
Django ORM: filtering users not on vacation [request creation]?
Good afternoon!
I just can't figure out how to make a request using Django ORM, I'm new to django.
class Employee(models.Model):
username = models.SlugField(unique=True)
class Vacation(models.Model):
employee = models.ForeignKey(Employee, on_delete=models.CASCADE)
start_date = models.DateField()
end_date = models.DataField()
class VacationReview(models.Model):
employee = models.ForeignKey(Employee, on_delete=models.CASCADE)
start_date = models.DateField()
end_date = models.DataField()
= no vacation records for employee
or ( ( date.now() < vacation.start or date.now() > vacation.end ) and no feedback records )
or ( there are feedback records and ( date.now() >= feedback .start and date.now() <= callback.end ) )
class EmployeesAtWorkView(LoginRequiredMixin, generic.ListView):
model = Employee
template_name = 'registry/employee_list.html'
def get_queryset(self):
date = timezone.now()
not_dismissal = Q(dismissal_date__isnull=True) | Q(dismissal_date__gt=date)
not_vacation = Q(vacation__isnull=True) | (Q(vacation__start_date__gt=date) | Q(vacation__end_date__lt=date))
is_vacation_review = Q(vacationreview__isnull=False) & (Q(vacationreview__start_date__lte=date) & Q(vacationreview__end_date__gte=date))
return Employee.objects.filter(
not_dismissal &
( not_vacation |
is_vacation_review )
)
class EmployeesVacationView(LoginRequiredMixin, generic.ListView):
model = Employee
template_name = 'registry/employee_list.html'
def get_queryset(self):
date = timezone.now()
not_dismissal = Q(dismissal_date__isnull=True) | Q(dismissal_date__gt=date)
is_vacation = Q(vacation__isnull=False) | (Q(vacation__start_date__lte=date) & Q(vacation__end_date__gte=date))
not_vacation_review = Q(vacationreview__isnull=True) | (Q(vacationreview__start_date__gt=date) | Q(vacationreview__end_date__lt=date))
return Employee.objects.filter(
not_dismissal &
is_vacation &
not_vacation_review
)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question