added identifier option to search

This commit is contained in:
MassiveAtoms 2020-07-15 00:34:44 -03:00
parent 5a83ccfc07
commit dc1571bcfb
8 changed files with 8 additions and 3 deletions

Binary file not shown.

View File

@ -6,7 +6,7 @@ from django.contrib.auth.models import User
class SearchForm(forms.Form):
title = forms.CharField(label="Title", max_length=200)
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)

View File

@ -57,7 +57,7 @@ class Data(models.Model):
class Identifier(models.Model):
book = models.IntegerField()
book = models.ForeignKey("Book", db_column="book", on_delete=models.CASCADE)
type = models.TextField()
val = models.TextField()

View File

@ -8,6 +8,8 @@
<input id="title" type="text" name="title" value="">
<label for="author">Author: </label>
<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>
</form>
</div>

View File

@ -1,6 +1,6 @@
from django.shortcuts import render
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 .forms import SearchForm, UserCreationForm
from django.db import models
@ -40,11 +40,14 @@ class ResultsView(generic.ListView): # no clue if this is secure.
def get_queryset(self): # new
title = self.request.GET.get('title')
author = self.request.GET.get('author')
identifier = self.request.GET.get("identifier")
books = Book.objects.prefetch_related("tags", "ratings")
if title:
books =books.filter(sort__icontains=title)
if author:
books = books.filter(author_sort__icontains=author)
if identifier:
books = books.filter(identifier__val=identifier)
return books