How to create orm query if data is exist or not ?

14 views
Skip to first unread message

Prashanth Patelc

unread,
Feb 23, 2023, 6:42:55 AM2/23/23
to django...@googlegroups.com
Hi all,

How to create orm query with data exist or not ?

How to check if approval_status Pending and Rejected with same user contains 

from_date       approval_status           User
2023-01-20  -     Approved                    NewUser
2023-01-12  -     Rejected                   NewUser
2023-01-06  -    Approved                   NewUser



If User contains above details in month between Create "
        Timesheet Model"     Eg:
Timesheet.objects.create(date=date,emaployee=emp,status=1)

leave_data = EmployeeLeaves.objects.filter(~Q(approval_status='Approved'),~Q(approval_status='Cancelled'),~Q(approval_status='Rejected'),
                                                   from_date__gte=month_first_date, to_date__lte=month_last_day,
                                                   employee=request.user).


If User Contains Pending Don't create Model  

leaves_data = EmployeeLeaves.objects.filter(~Q(approval_status='Pending'),
                                                    from_date__gte=month_first_date, to_date__lte=month_last_day,
                                                    employee=request.user).

Prashanth Patelc

unread,
Feb 23, 2023, 7:11:34 AM2/23/23
to django...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages