fiksedillet litt mer på søk. Dette skal nå være fungerende
This commit is contained in:
parent
35d0a09728
commit
8f1a033456
|
@ -16,13 +16,14 @@ def search_book_cmd(search_strings, search_description=False):
|
||||||
print format % (book.isbn, b_id, title, authors_str)
|
print format % (book.isbn, b_id, title, authors_str)
|
||||||
|
|
||||||
def search_book(search_strings, search_description=False):
|
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:
|
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(subtitle__icontains=word) |
|
||||||
|
Q(alt_titles__alt_title__icontains=word) |
|
||||||
Q(id__id__icontains=word) |
|
Q(id__id__icontains=word) |
|
||||||
Q(person__person__first_name__icontains=word) |
|
Q(persons__person__first_name__icontains=word) |
|
||||||
Q(person__person__last_name__icontains=word))
|
Q(persons__person__last_name__icontains=word))
|
||||||
return remove_duplicates(basic_query.all())
|
return remove_duplicates(basic_query.all())
|
||||||
|
|
||||||
def remove_duplicates(list):
|
def remove_duplicates(list):
|
||||||
|
|
|
@ -62,7 +62,7 @@ class Book(models.Model):
|
||||||
# return Book.get(isbn=self.isbn)
|
# return Book.get(isbn=self.isbn)
|
||||||
|
|
||||||
def get_authors(self):
|
def get_authors(self):
|
||||||
people = self.person.all()
|
people = self.persons.all()
|
||||||
authors = []
|
authors = []
|
||||||
for person in people:
|
for person in people:
|
||||||
if person.relation.name == 'Author':
|
if person.relation.name == 'Author':
|
||||||
|
@ -101,13 +101,13 @@ class Person(models.Model):
|
||||||
return self.first_name + u' ' + self.last_name
|
return self.first_name + u' ' + self.last_name
|
||||||
|
|
||||||
class Relation(models.Model):
|
class Relation(models.Model):
|
||||||
name = models.CharField(max_length=31)
|
name = models.CharField(max_length=31, primary_key=True)
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
class BookPerson(models.Model):
|
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')
|
person = models.ForeignKey(Person, related_name='books')
|
||||||
relation = models.ForeignKey(Relation)
|
relation = models.ForeignKey(Relation)
|
||||||
|
|
||||||
|
|
Reference in New Issue