So I want to create a super basic form with a single input field which will be used to query my database.
My model (models.py) is as follows:
You can do a simple search here. You do not need any POST calls or form creation. However, if you want to create a form this should still point you in the correct direction.
Try something like this:
search.html:
views.py:
from myapp.models import Book
from django.template import RequestContext
from django.shortcuts import render_to_response
def search(request):
query = request.GET.get('q')
try:
query = int(query)
except ValueError:
query = None
results = None
if query:
results = Book.objects.get(uid=query)
context = RequestContext(request)
return render_to_response('results.html', {"results": results,}, context_instance=context)
results.html:
{% if results %}
{% for result in results %}
{{ result.uid }}
{{ result.xxxx }}
{{ result.xxxx }}
{% endfor %}
{% else %}
Please enter a valid UID
{% endif %}