I'm very new to Django and need help with a simple task. I have two templates.
search.html
: renders a simple form with a text field an a submit button and POSTs to/search_results/
search_results.html
: need to render the result of database query POSTed to/search_results/
In my forms.py
file:
from django import forms
class SystemsForm(forms.Form):
serial_num = form.CharField(label="Serial no.", max_length=45)
In my urls.py
urlpatterns = patterns('',
url(r'^search/$', SystemSearch.as_view()),
url(r'^search_results/$', SystemResult.as_view()),
)
In my views.py file
from django.views.generic.edit import FormView
from inventory.forms import SystemsForm
class SystemSearch(FormView):
# For displaying the form
template_name = 'inventory/search.html'
form_class = SystemsForm
class SystemResult(FormView):
template_name = 'inventory/search_result.html'
form_class = SystemsForm
# How to do these two things?
# Query the database model called Systems with the POST data
# -- Systems.objects.get(serial_num=??)
# pass context to search_result.html
I'm not even sure if I'm heading in the correct direction or completely off from what I should be doing.