user12140833
user12140833

Reputation: 179

Getting multiple queryset list of single model

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

Upvotes: 1

Views: 412

Answers (1)

Co Worker
Co Worker

Reputation: 139

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

Upvotes: 1

Related Questions