thanku very much..... On May 9, 11:02 pm, Jani Tiainen <rede...@gmail.com> wrote: > On Mon, 2011-05-09 at 06:15 -0700, pankaj sharma wrote: > > i have 4 branches in a college.. > > some college have three some have 4 and so on.... > > so i want to provide a search system to the user that they can see the > > list of all the colleges which are having some branch say branch2 may > > be he can select branch 3 and 4 and 1 also > > so i am taking a query from the user for the branch so that i can > > filter all the colleges having that branch..... > > > no i did this .. > > i took a query say B {and the calue of B may be branch 1, branch 2, > > 3,&4 as i have given a selectbox to user to select any branch} > > now in filter tag i did this > > > college_list = College.objects.filter(B=True) > > > but it is not working... so please tell me > > You have to construct your HTML to be something like this: > > <select name="branch"> > <option value="branch1">Branch 1</option> > <option value="branch2">Branch 2</option> > <option value="branch3">Branch 3</option> > <option value="branch4">Branch 4</option> > </select> > > And in code: > # Retrieve branch column name: > branch = form.cleaned_data['branch'] > > # Build kwargs dictionary. > # See python docs about keyword argument expansion > branch_kwargs = { branch : True } > > # Create Q object (not necessary, see below) > branch_q = Q(**branch_kwargs) > > # Filter > college_list = College.objects.filter(branch_q) > > note that branch_q construction is not necessary, you can do it > directly: > > college_list = College.objects.filter(**branch_kwargs) > > -- > > Jani Tiainen
-- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@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.