added identifier option to search
This commit is contained in:
parent
5a83ccfc07
commit
dc1571bcfb
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -6,7 +6,7 @@ from django.contrib.auth.models import User
|
|||||||
class SearchForm(forms.Form):
|
class SearchForm(forms.Form):
|
||||||
title = forms.CharField(label="Title", max_length=200)
|
title = forms.CharField(label="Title", max_length=200)
|
||||||
author = forms.CharField(label='Author', max_length=100)
|
author = forms.CharField(label='Author', max_length=100)
|
||||||
# identifier = forms.CharField(label='Identifier(ISBN, Google-id, amazon id)', max_length=20)
|
identifier = forms.CharField(label='Identifier(ISBN, Google-id, amazon id)', max_length=20)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ class Data(models.Model):
|
|||||||
|
|
||||||
|
|
||||||
class Identifier(models.Model):
|
class Identifier(models.Model):
|
||||||
book = models.IntegerField()
|
book = models.ForeignKey("Book", db_column="book", on_delete=models.CASCADE)
|
||||||
type = models.TextField()
|
type = models.TextField()
|
||||||
val = models.TextField()
|
val = models.TextField()
|
||||||
|
|
||||||
|
@ -8,6 +8,8 @@
|
|||||||
<input id="title" type="text" name="title" value="">
|
<input id="title" type="text" name="title" value="">
|
||||||
<label for="author">Author: </label>
|
<label for="author">Author: </label>
|
||||||
<input id="author" type="text" name="author" value="">
|
<input id="author" type="text" name="author" value="">
|
||||||
|
<label for="author">Identifier: </label>
|
||||||
|
<input id="identifier" type="text" name="identifier" value="">
|
||||||
<button class="waves-effect waves-light btn green accent-4" type="submit">search</button>
|
<button class="waves-effect waves-light btn green accent-4" type="submit">search</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from django.views import generic
|
from django.views import generic
|
||||||
from .models import Author, Book, Comment, Rating, BookAuthorLink, Publisher, Tag, BookTagLink, BookRatingLink, Data
|
from .models import Author, Book, Comment, Rating, BookAuthorLink, Publisher, Tag, BookTagLink, BookRatingLink, Data, Identifier
|
||||||
from django.http import HttpResponseRedirect
|
from django.http import HttpResponseRedirect
|
||||||
from .forms import SearchForm, UserCreationForm
|
from .forms import SearchForm, UserCreationForm
|
||||||
from django.db import models
|
from django.db import models
|
||||||
@ -40,11 +40,14 @@ class ResultsView(generic.ListView): # no clue if this is secure.
|
|||||||
def get_queryset(self): # new
|
def get_queryset(self): # new
|
||||||
title = self.request.GET.get('title')
|
title = self.request.GET.get('title')
|
||||||
author = self.request.GET.get('author')
|
author = self.request.GET.get('author')
|
||||||
|
identifier = self.request.GET.get("identifier")
|
||||||
books = Book.objects.prefetch_related("tags", "ratings")
|
books = Book.objects.prefetch_related("tags", "ratings")
|
||||||
if title:
|
if title:
|
||||||
books =books.filter(sort__icontains=title)
|
books =books.filter(sort__icontains=title)
|
||||||
if author:
|
if author:
|
||||||
books = books.filter(author_sort__icontains=author)
|
books = books.filter(author_sort__icontains=author)
|
||||||
|
if identifier:
|
||||||
|
books = books.filter(identifier__val=identifier)
|
||||||
return books
|
return books
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user