diff --git a/python/search.py b/python/search.py index 5ac79a5..fa5c66b 100644 --- a/python/search.py +++ b/python/search.py @@ -16,13 +16,14 @@ def search_book_cmd(search_strings, search_description=False): print format % (book.isbn, b_id, title, authors_str) def search_book(search_strings, search_description=False): - basic_query = Book.objects.select_related('person__person','id') + basic_query = Book.objects.select_related('persons__person','id','alt_titles') for word in search_strings: - basic_query=basic_query.filter(Q(title__icontains=word) | + basic_query=basic_query.filter(Q(title__icontains=word) | Q(subtitle__icontains=word) | + Q(alt_titles__alt_title__icontains=word) | Q(id__id__icontains=word) | - Q(person__person__first_name__icontains=word) | - Q(person__person__last_name__icontains=word)) + Q(persons__person__first_name__icontains=word) | + Q(persons__person__last_name__icontains=word)) return remove_duplicates(basic_query.all()) def remove_duplicates(list): diff --git a/python/web/library/models.py b/python/web/library/models.py index e24b4f8..8f2857e 100644 --- a/python/web/library/models.py +++ b/python/web/library/models.py @@ -62,7 +62,7 @@ class Book(models.Model): # return Book.get(isbn=self.isbn) def get_authors(self): - people = self.person.all() + people = self.persons.all() authors = [] for person in people: if person.relation.name == 'Author': @@ -101,13 +101,13 @@ class Person(models.Model): return self.first_name + u' ' + self.last_name class Relation(models.Model): - name = models.CharField(max_length=31) + name = models.CharField(max_length=31, primary_key=True) def __unicode__(self): return self.name class BookPerson(models.Model): - book = models.ForeignKey(Book, related_name='person') + book = models.ForeignKey(Book, related_name='persons') person = models.ForeignKey(Person, related_name='books') relation = models.ForeignKey(Relation)