Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

340
Vistas
How do you combine two querysets into one queryset(not a list) in django?

I want to simply combine two querysets from different models into one queryset (and not a list as shown in other stackoverflow questions!). For example, here are two querysets:

a = Modelone.objects.all()
b = Modeltwo.objects.filter(number__gte=4)

Then, I want a queryset c that combines both a and b. Thank you, and please leave me any questions you have.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You cannot do that. Imagine the following:

class Modelone(models.model):
 number = models.IntegerField()

class Modeltwo(models.model):
 text = models.TextField()

Imagine you would filter against your joined queryset, how can that work if the rows (or instances) do not have the same fields?

If you would want to join two querysets of the same model, you could do that:

qs1 = modelone.objects.filter(nummber=10)
qs2 = modelone.objects.filter(nummber=20)
joined = qs1 | qs2

(source)

If your two models are similar and have overlapping fields, you could use something like django-polymorphic

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda