Searching for records
Searching for records is also a common operation in business logic methods. There are many cases where we need to search the data based on different criteria. Finding the room by name and category is demonstrated in this tutorial.
Getting ready
This tutorial will use the same hostel.room
definition as the Creating new records tutorial did previously. We will write the code in a method called find_room(self)
.
How to do it…
To find the rooms, you need to perform the following steps:
- Add the
find_room
method to thehostel.room
model:def find_room(self): Â Â Â Â ...
- Write the search domain for your criteria:
domain = [ Â Â Â Â '|', Â Â Â Â Â Â Â Â '&', ('name', 'ilike', 'Room Name'), Â Â Â Â Â Â Â Â Â Â Â Â Â ('category_id.name', 'ilike', 'Category...