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

  • Home
  • SEARCH
  • 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 8876321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:11:13+00:00 2026-06-14T19:11:13+00:00

I got a serach box in my project, the thing is that a user

  • 0

I got a serach box in my project, the thing is that a user can enter any keyword and my ModelForm filters the fields I explicitly tell to filter, I use the following piece of code in my Form:

def get_matching_siniestros(self):
    if self.cleaned_data['keywords'] is None:
        return None
    matching = []
    for kw in self.cleaned_data['keywords']:
        numero_ajuste = Siniestro.objects.filter(
            numero_ajuste__icontains=kw
        )

        nombre_contratante = Siniestro.objects.filter(
            poliza__contratante__nombre__icontains=kw
        )


        matching = chain(
            numero_ajuste, 
            nombre_contratante,
            matching
        )

    # verify not repeated Siniestro
    non_rep_siniestros = []
    for siniestro in matching:
        if siniestro not in non_rep_siniestros:
            non_rep_siniestros.append(siniestro)

    return non_rep_siniestros

What I want to do is to programatically filter on any CharField in the Model and also if possible on any CharField of nested relations, in this example Siniestro has a FK to poliza and poliza has an FK to contratante.

  • 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-14T19:11:14+00:00Added an answer on June 14, 2026 at 7:11 pm

    You can iterate over every field and do whatever you like, e.g.:

    [process(field) for field in model._meta.fields if field.__class__ == CharField]
    

    where process can be a function, or whatever you require.

    That said, I should really point out that the complexity you’re trying to involve is bound to get messy. IMO, have a look at django-haystack. Indexing should be the way to go.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a search box that users can type terms into. I have a
I've got a MVC 3 view which displays a list of items that can
I have got an asp.net form, with a jqgrid on it. The user can
So I got a search box in a site we're developing that will search
I've got a search box that is supposed to be able to search data
I've got an MVC3 web application that has a general search box and displays
I did search, and got a cloeset answer form How can I automatically close
I've got a Ticket model that I'm trying to search by its IntegerField priority
i've got a few questions about applets in java. Let's say that my app
I've got a script that disables a button input control, empties a table body

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.