thanks for ur answer jani but i didn't get it . as i am getting one
query for branch {which is Qbranch} so where i use this?

On May 8, 10:40 pm, Jani Tiainen <rede...@gmail.com> wrote:
> On Sun, 2011-05-08 at 09:59 -0700, pankaj sharma wrote:
> > hello ..
>
> > i am having a database of college  which have a name city state
> > branches etc...
> > so
>
> > class College(models.Model):
>
> >    name = models.CharField(max_length=250)
>
> >    city = models.ForeignKey(City)
>
> >    branch1 = models.BooleanField(default=False, blank=True)
> >    branch2 = models.BooleanField(default=False, blank=True)
> >    branch3 = models.BooleanField(default=False, blank=True)
> >    branch4 = models.BooleanField(default=False, blank=True)
>
> > now i want to provide user that they can search colleges from
> > branches..
> > so i am giving them a select box where they can select the city and
> > branches
> > suppose i get two queries Qcity and Qbranch
> > so i will filter all the colleges having city = Qcity and
> > Branches=Qbranch
> > so please tell me how to filter
>
> > i have filtered city but how to add one another filter for branch {as
> > it is bolleanfield}
> > college_list = College.objects.filter(city__title__icontains=Qcity)
>
> In case of branch1:
> college_list = College.objects.filter(city__title__icontains=Qcity,
> branch1=True)
>
> if you want to search multiple branches:
>
> branches_query = Q(branch1=True) | Q(branch2=True)
> college_list = College.objects.filter(branches_query,
> city__title__icontains=Qcity)
>
> Though since you have boolean field that will always be either true or
> false, you can construct:
>
> branches_query=Q(branch1=branch1_form_field_value) |
> Q(branch2=branch2_form_field_value) | ...
>
> --
>
> 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.

Reply via email to