OK the simplest solution is something like that.
I make some assumptions about the structure of your models, so
adjust accordingly.
Let's say this is our models.py
from django.db import models
class Director(models.Model):
name = models.CharField(max_length=128)
# maybe some other fields...
class Film(models.Model):
title = models.CharField(max_length=128)
director = models.ForeignKey(Director)
created_at = models.DateField()
Our naive views.py
Please keep in mind that I deliberately omit many sanity checks.
import datetime
from django.shortcuts import render_to_response
from myapp.models import Film
def search(request):
# Suppose we support these params -> ('director', 'fromdate', 'todate')
request_params = request.GET.copy()
fromdate = datetime.datetime.strptime(request_params['fromdate'], 'some-string-format')
todate = datetime.datetime.strptime(request_params['todate'], 'some-string-format')
# Our query is ready to take off.
film_results = Film.objects.filter(
director__name=request_params['director'],
created_at__range=(fromdate, todate)
)
return render_to_response('search_results.html', {'results':film_results})
Our search_results.html template
{% extends some_base.html %}
{% if results }
{% for film in results %}
<h3>{{ film.title }}</h3>
<p>Director: {{ film.director.name }}</p>
<p>When: {{ film.created_at }}</p>
{% endfor %}
{% else %}
<p>Sorry no results for your query</p>
{% endif %}
Also read this on creating datetime objects from string
Edit: Oh I forgot about the urls.py and the actual form :)
in your url.py add something like this inside the urlpatterns.
url(r'^search/$', 'myapp.views.search'),
Now the actual search form must be something like this:
<form method='GET', action='/search/'>
... your fields
</form>
You can generate it through a django form if you wish.
Anyway this is not going to get you far I guess. If you are doing
anything serious you might take a look into haystack