Django Filter Query Exception
While looking for answers on this question: “Does multiple monitor increase programmer’s productivity?”, I found interesting tips from Joelon Software blog post. It’s the fourth Joel’s Test: A Bug Database.
Since, I still don’t know yet what tool will help us to store our bugs, I’ll write my first bug in this blog post. And also I’d like to know how to write snippet in Jekyll, which powered this blog.
So, let’s give it a shot!
Example, I am querying database using Django query filter.
This code will not return the exception eventhough there is no match with the filter rule. No match filter query will only return empty list. So, I need to fix the code.
Let’s try to debug using the django shell.
So user u1 doesn’t borrow any books while u2 borrows 2 books. What to do to improve this code? We could check the query length. If the query length equalas to zero then we could throw the exception.
That’s all for now.