Django: Filter a Queryset made of unions not working

前端 未结 3 1510
一向
一向 2021-02-13 14:53

I defined 3 models related with M2M relationsships

class Suite(models.Model):
    name = models.CharField(max_length=250)
    title = models.CharField(max_length         


        
3条回答
  •  不思量自难忘°
    2021-02-13 15:28

    I had the same issue and ended up using the union query as a subquery so that the filters could work:

    yourModelUnionSubQuerySet = YourModelQS1.union(YourModelQS2)
    yourModelUnionQuerySet = YourModel.objects.filter(id__in=yourModelUnionSubQuerySet.values('id'))
    

提交回复
热议问题