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 6972327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:57:13+00:00 2026-05-27T16:57:13+00:00

After a search of a database I end up with an array of querysets.

  • 0

After a search of a database I end up with an array of querysets. I wanted to concatenate these queryset somewhat like we can do with list elements. Is this possible or maybe there an altogether better way to do this? The end goal here is to get queryset for rows of table that contain one of a set of strings in a field.

for i in range(0,(searchDiff+1)):
    filterString = str(int(searchRange[0]) + i)
    myQuerySetTwoD.append(my.objects.filter(asn=filterString))
    for j in range(0,(len(myQuerySetTwoD)-1)):
        myQuerySet = myQuerySet + myQuerySetTwoD[j]

UPDATE: Found my own answer (something about writing the question down maybe)

Just

from itertools import chain

then replace

myQuerySet = myQuerySet + myQuerySetTwoD[j]

with

BgpAsnList = chain(BgpAsnList,BgpAsnListTwoD[j])
  • 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-05-27T16:57:13+00:00Added an answer on May 27, 2026 at 4:57 pm

    Your code looks weird! I have no idea how does it work and what you are doing here, but here is how I would do the query thing instead:

    from django.db.models import Q
    
    myQuery = Q()
    for i in range(0,(searchDiff+1)):
        filterString = str(int(searchRange[0]) + i)
        myQueryTwoD.append(Q(asn=filterString))
        for j in range(0,(len(myQueryTwoD)-1)):
            myQuery = myQuery | myQueryTwoD[j]
    
    myQuerySet = my.objects.filter(myQuery)
    

    How does it work?

    Blagh.objects.filter(Q(smth='A') | Q(smth='B'))
      will generate query which looks like:
    SELECT ... from blagh WHERE smth = 'A' OR smth = 'B'
    

    Take a look and django docs: Complex lookups with Q object

    Your method with itertools will result in many queries to database. With my solution it will be one query with OR lookup in WHERE clause.

    Update:

    Maybe even better solution would be something like this:

    strings = []
    for i in range(0,(searchDiff+1)):
        filterString = str(int(searchRange[0]) + i)
        strings.append(filterString)
    
    my_query_set = MyModel.objects.filter(arn__in=strings)
    

    I fail to understand why do you need that inner loops…

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

Sidebar

Related Questions

After a several hour (re)search, I just can't come up with a explainable difference
Im not sure how to correct these errors, can someone help me. search.php Notice:
In my Drupal 7 site, users will fill a form. After some search i
After having a search around I could not find exactly what I want, I
After a painful search for Python XMPP library to use for XEP 060 I
After an extensive search I have been unable to find any information on this
Does jqGrid just have any callback after single field search? The onSearch callback fires
so here's the problem I have one form, it outputs search results after submit,
After lots of attempts and search I have never found a satisfactory way to
After doing a long search on stackoverflow i didn't find any one talked about

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.