From 8f1a033456466928377532c236a3e077c48ad85d Mon Sep 17 00:00:00 2001 From: almelid Date: Mon, 27 Sep 2010 20:44:57 +0000 Subject: [PATCH] =?UTF-8?q?fiksedillet=20litt=20mer=20p=C3=A5=20s=C3=B8k.?= =?UTF-8?q?=20Dette=20skal=20n=C3=A5=20v=C3=A6re=20fungerende?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- python/search.py | 9 +++++---- python/web/library/models.py | 6 +++--- 2 files changed, 8 insertions(+), 7 deletions(-) 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)