Combine Two Querysets With Different Models

By admin ·
1

Combine Two Querysets With Different Models

We can obviously have a parent class in this case with common properties, but we are keeping it simple for purposes of this tutorial.

Notice the object types here are of type Bmw and Tesla.

If you can set up your models from scratch, you can think about a better design, where you store the type of a Car like ‘Tesla’ , ‘BMW’ in a separate table, and have a Foreign Key to your Cars table as a better alternative. The ‘contenttypes framework’ could come in handy, when you don’t have the liberty to change existing models a.k.a production