I am trying to build a search form with multiple filters/input
objects. Basically, i want to be able to allow for a simple searhc
based on one criteria or multiple. So if someone searches the name
field(q) they can filter by political party, or city, etc.  Also, I
would like to be able to return results without a search in the name
field(q)

Here is my model:

class Rep(models.Models):

    Type = models.CharField(max_length=100, choices=Type_Choices,
blank=True)
    Last_Name = models.CharField('Last Name', max_length=100,
blank=True)
    First_Name = models.CharField('First Name', max_length=100,
blank=True)
    Position = models.CharField('Position', help_text="Only used for
non-council City and Local officials", max_length=100, blank=True,
choices=Position_Choices)
    Party = models.CharField(max_length=3, choices=Party_Choices,
blank=True)
    District = models.IntegerField(help_text="For State, Federal and
County Commissioners", blank=True, null=True)
    Ward = models.IntegerField(help_text="For City Councils",
blank=True, null=True)
    City = models.CharField(max_length=100, blank=True)
    Phone = models.CharField(max_length=15, help_text="Use the form
(xxx) xxx-xxxx", blank=True)
    Email = models.EmailField(max_length=100, blank=True)
    Contact_URL = models.URLField(max_length=200, blank=True)
    DOB = models.DateField('Date of Birth',blank=True, null=True)
    Gender = models.CharField(blank=True, max_length=2,
choices=Gender_Choices)
    Begin_Serve = models.IntegerField('Began Serving in', blank=True,
null=True)
    End_Serve = models.IntegerField('Term Limited in', blank=True,
null=True)
    MugShot = models.ImageField('Mug Shot Upload', help_text="images
are to be no larger that 150x200", storage=s3_storage,
upload_to='newsok/images/Government/images', height_field=None,
width_field=None, max_length=300, blank=True)
    Committees = models.ManyToManyField('Committees', blank=True)
    Approp_Committee = models.ManyToManyField('Approp_Committees',
blank=True)

my view (the search view):


def search(request):
    error = False
    if 'q' in request.GET:
        q = request.GET.['q']
        reps = Rep.objects.filter(Last_Name__contains=q)
        if 'party' in request.GET:
            party = request.GET.['party']
            reps = reps.filter(Party__contains=party)
        return render_to_response('Government/search_results.html',
            {'reps': reps, 'query': q})
    return render_to_response('Government/search.html', {'error':
error})


my tpl:
<html>
<body>
{% if error %}
        <p style="red">Please submit a valid search</p>
{% endif %}
        <form action="" method="get">
                <input type"text" name="q"><br />
                <h2>Party</h2>
                <input type="checkbox" name="party" value="d">
Democrat<br />
                <input type="checkbox" name="party" value="r">
Republican<br />
                <input type="submit" value="Search">
        </form>
</body>
</html>

It is set up now where I can search against the "q" and filter it
based on the "party" but I can't go beyond that. I'd like to add
district, city, and term limited in fields and have them all build on
one another. But the way I have it now I don't think I can do that.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to