1

I have a model say:

class Abc(models.model):
    ....
    .....

Now When performing query(let go all the imports):

print(Abc.objects.all())

I am getting multiple lists of querySet:

Output as

<QuerySet [<Abc: ...>, <Abc: .....> , .....]> <QuerySet [<Abc: ...>, <Abc: .....> , .....]>

I have to User so I am getting 2 different QuerySet. How can I get all the user's querySet in single list,

Wanted output as:

<QuerySet [<Abc: ...>, <Abc: .....> , .....]>, <QuerySet [<Abc: ...>, <Abc: .....> , .....]> or in a single list <QuerySet [<Abc: ...>, <Abc: .....> , .....]>

But from my knowledge a model should list all the querySet in a single list, why am I getting multiple lists? Image of my model and error

3
  • 1
    print(Abc.objects.all()) will print the only single queryset. In your case, there may be a chance for you may be calling it twice. You can verify that by calling it from Django Shell Commented Nov 18, 2019 at 2:59
  • Does the list_display in django Admin calls the method as many times the object is present in the list ? Commented Nov 18, 2019 at 3:08
  • No. It won't call N times Commented Nov 18, 2019 at 3:12

1 Answer 1

1

I think you can use the union function to do that. See the document for more detail: https://docs.djangoproject.com/en/2.2/ref/models/querysets/#union

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.