How it works...

The implementation of the filter() method creates an empty recordset in which all the records for which the predicate function evaluates to True are added. The new recordset is finally returned. The order of records in the original recordset is preserved.

The preceding recipe used a named internal function. For such simple predicates, you will often find an anonymous lambda function being used:

@api.model 
def books_with_multiple_authors(self, all_books): 
    return all_books.filter(lambda b: len(b.author_ids) > 1) 

Actually, you need to filter a recordset based on the fact that the value of a field is truthy in the Python sense (non-empty strings, non-zero numbers, non-empty containers, and so on). So, if you want to filter records that have a category set, you can pass the field name to filter like this: all_books.filter('category_id').

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset