--- /dev/null
+from quotes.models import Quote
+
+def search(pattern):
+ results = {}
+
+ results['quotes'] = Quote.objects.filter(text__contains=pattern)
+ return results
--- /dev/null
+{% extends 'quotes/base.html' %}
+
+{% block title %}Searching for quotes{% endblock %}
+
+{% block body %}
+
+{% for quote in quotes %}
+ {% include "quotes/display.html" with quote=quote %}
+{% endfor %}
+
+<hr />
+
+<form action="{% url 'quotes:search' %}" method="post">
+ {% csrf_token %}
+ Search: <input type="text" name="q" />
+ <input type="submit" value="Vote" />
+</form>
+
+{% endblock %}
urlpatterns = [
url(r'^$', views.random, name='random'),
+
url(r'^random$', views.random, name='random'),
url(r'^random/$', views.random, name='random'),
+
url(r'^show/(?P<quote_id>[0-9]+)/$', views.onequote, name="onequote"),
url(r'^tag/(?P<tag_id>[0-9]+)/$', views.tags, name="tags"),
url(r'^author/(?P<author_id>[0-9]+)/$', views.author, name="author"),
url(r'^work/(?P<work_id>[0-9]+)/$', views.work, name="work"),
+
+ url(r'^search/$', views.searchpage, name="search"),
+
url(r'^all/$', views.all, name="all"),
]
from random import randint
-from .models import Author, Work, Quote, QuoteTag
+from quotes.models import Author, Work, Quote, QuoteTag
+import quotes.search as search
# Create your views here.
def onequote(request, quote_id):
quotes = Quote.objects.all()
context = { 'quotes' : quotes }
return render(request, 'quotes/all.html', context)
+
+def searchpage(request):
+ results = {}
+ if 'q' in request.POST:
+ results = search.search(request.POST['q'])
+ return render(request, 'quotes/search.html', results)