Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8893401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:14:19+00:00 2026-06-14T23:14:19+00:00

I have simple search application How can I search by Categories using <select><option></select> the

  • 0

I have simple search application
How can I search by Categories
using <select><option></select>

the result :

results = Adv.objects.filter(title__icontains=query).filter(cate__name__icontains=query)

here is the code :

models

class Category(models.Model):
    slug = models.SlugField(unique=True)
    name = models.CharField(max_length=60)

class Adv(models.Model):
    title = models.CharField(max_length=60)
    pub_date = models.DateTimeField(auto_now_add=True)
    namecar = models.CharField(max_length=60)
    cate = models.ForeignKey(Category)

view

def search(request):
    if 'q' in request.GET:
      query = request.GET['q']
      results = Adv.objects.filter(title__icontains=query).filter(cate__name__icontains=query)
   #   print results.query 
    else:
      query = ""
      results = None
    template = loader.get_template('search/search1.html')
    context = Context({ 'query': query, 'results': results, 'city_list': ChoiceCity.objects.all() })
    response = template.render(context)
    return HttpResponse(response) 

url

(r'^search1/$', 'car.search.views.search'),

template

<form method="get" action="/search1/">
<p><label for="id_q">Search:</label>
<input type="text" name="q" id="id_q" value="{{ query }}" />
<input type="submit" value="Submit" /></p>
</form>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T23:14:20+00:00Added an answer on June 14, 2026 at 11:14 pm

    I guess you want to be able to filter the result based on the category. I would suggest adding a category selection drop down in your template. This would require you to send the category objects into the template so, it could be rendered

    <form method="get" action="/search1/">
    <p><label for="id_q">Search:</label>
    <input type="text" name="q" id="id_q" value="{{ query }}" />
    <select name="category">
      {% for category in categories %}
        <option value="{{category.id}}">{{category.name}}</option>
      {% endfor %}  
    </select>
    <input type="submit" value="Submit" /></p>
    </form>
    
    
    
     def search(request):
            if 'q' in request.GET:
              #Get the selected category id 
              sel_category = request.GET.get('category', None)
              #If it exists, get the category object
              if sel_category: 
                    category = get_object_or_404(Category, pk = sel_category)
              query = request.GET['q']
              results = Adv.objects.filter(title__icontains=query)
              #If category objects exists filter the result set based on that
              if category:
                        results =results.filter(cate__name__icontains=category.name)
           #   print results.query 
            else:
              query = ""
              results = None
              categories = Category.objects.all()
            template = loader.get_template('search/search1.html')
            context = Context({ 'query': query, 'results': results, 'city_list': ChoiceCity.objects.all(), 'categories':categories })
            response = template.render(context)
            return HttpResponse(response) 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

riting a very simple search using like and have an option to omit options,
In our desktop application, we have implemented a simple search engine using an inverted
On my homepage I have a simple search form. The user can enter some
I have developed a simple application for study of sql injection where i search
I have an asp.net application with a search page, with criteria and result display
I have a simple search working in my rails app, but it only searches
I have a simple search box that it hidden until hover(over) and hides again
I have a simple search form with a box and a button. <form action
I have a simple rails search implemented in my app. At the time I
I'm making a simple search form in rails. In my search view I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.