filter

28 views
Skip to first unread message

sum abiut

unread,
Jan 15, 2015, 6:41:10 PM1/15/15
to django...@googlegroups.com


Hi,
I am trying to two column and display some result if two conditions are meet but i am getting this error:
The view eLeave.views.FMKD1_leave_to_authorize didn't return an HttpResponse object. It returned None instead.

I can seems to figure out the issue, here is my view.py file

def FMKD1_leave_to_authorize(request):
    new_leave =newleave.objects.filter(department_head_authorization="Approved" )
    a = newleave.objects.filter(department="FMKD")
    if new_leave=="True"and a =="True":
        return render_to_response('FMKD1_display_approve_leave.html', locals())

Vijay Khemlani

unread,
Jan 15, 2015, 6:53:15 PM1/15/15
to django...@googlegroups.com
in your view new_leave and a are QuerySet objects, and then you are comparing them to a string ("True") not a bolean (True without quotes), so it's always False.

Even if you change "True" to True it won't work, try it like this

if new_leave.exists() and a.exists():
  return ...


--
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 django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAPCf-y7uRsM8Vx6Jj5QD4ZY%2BCk24SkgCHZv-xMGZr49icPrmrA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

sum abiut

unread,
Jan 15, 2015, 7:49:00 PM1/15/15
to django...@googlegroups.com
Ok thanks,

i just released that i have made a mistake. so basically here are my template.html and view.py
i think there is a mistake in my view.py the display result is not what i was looking for. can't seem to figure it out.

template.html

<table id="t01" >
<tr>
<th>Select to approve leave</th>
  <th>First Name</th>
  <th>Last Name</th>
  <th>Position</th>
  <th>Department</th>
  <th>Leave Type</th>
  <th>Details</th>
  <th>Start Date</th>
  <th>End Date</th>
  <th>Total working days</th>
  <th># of leave left</th>
  <th> Department Head Authorization</th>
  <th>Authorize By</th>
  <th> Remarks</th>
  <th>Authorized Date</th>
 
</tr>
{%for a in new_leave%}
<tr>
<td><a href ="/authorized_Leave/{{ a.id}}/"><input type="checkbox" onClick="parent.location='#'" > </a> </td>
<td>{{a.first_name}}</td>
  <td>{{a.last_name}}</td>
  <td>{{a.position}}</td>
  <td>{{a.department}}</td>
<td>{{a.leave_type}}</td>
  <td>{{a.specify_details}}</td>
  <td>{{a.start_date}}</td>
  <td>{{a.end_date}}</td>
  <td>{{a.total_working_days}}</td>
  <td>{{a.total_Leave_Left}}</td>
   <td>{{a.department_head_authorization}}</td>
    <td>{{a.authorized_by}}</td>
     <td>{{a.remarks}}</td>
     <td>{{a.authorization_date}}</td>

  </tr>
{%endfor%}
</table>



view.py



def FMKD1_leave_to_authorize(request):
    new_leave =newleave.objects.filter(department_head_authorization="Approved" )
    new_leave = newleave.objects.filter(department="FMKD")
    if new_leave.exists() and new_leave.exists():

Vijay Khemlani

unread,
Jan 15, 2015, 7:58:23 PM1/15/15
to django...@googlegroups.com
What are you expecting to see? What are you actually seeing?

sum abiut

unread,
Jan 15, 2015, 10:01:46 PM1/15/15
to django...@googlegroups.com
i expect to see only the data that have department_head_authorization="Approved" and department="FMKD" showing but instead the data that the department_head_authorization is not Approved is also showing.




For more options, visit https://groups.google.com/d/optout.



--

Erik Cederstrand

unread,
Jan 16, 2015, 4:04:10 AM1/16/15
to Django Users
You're overwriting one QuerySet with another:

new_leave =newleave.objects.filter(department_head_authorization="Approved" )
new_leave = newleave.objects.filter(department="FMKD")

Instead, do this:

new_leave = newleave.objects.filter(department_head_authorization="Approved", department="FMKD")


Erik
> To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAPCf-y5zJBczvqoPk%3DbaOgD6Ap0mM32N3jH71vz_XBmY4GBXzA%40mail.gmail.com.

Abraham Varricatt

unread,
Jan 19, 2015, 4:32:07 AM1/19/15
to django...@googlegroups.com
In addition to the other answers, I will suggest that you re-think your view logic - you haven't handled the case where your IF block fails. Remember, Django expects every view function to return a HttpResponse object. Assume that someone's request isn't authorized (yet) or even rejected. What do you want them to see? It's good user experience to at least show an error message instead of throwing them back to the home-page.

-Abraham V.

sum abiut

unread,
Jan 19, 2015, 5:52:07 PM1/19/15
to django...@googlegroups.com
Thanks very much for all the help I am getting from you guys. your help is very much appreciated.

cheers,


--
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 django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.

For more options, visit https://groups.google.com/d/optout.



-
Reply all
Reply to author
Forward
0 new messages