0
이 질문은 this one으로 확대됩니다.django-filter 및 DRF : lookupfield의 AND 절
내 모델
class Car(models.Model):
images = models.ManyToManyField(Image)
class Image(models.Model):
path = models.CharField()
type = models.CharField()
을하고 내 필터 클래스가
class CarFilter(django_filters.FilterSet):
having_image = django_filters.Filter(name="images", lookup_type='in')
class Meta:
model = Car
다음 내가
?having_image=5
같은 쿼리를 GET하고
pk=5
와 이미지가 모든 차를 얻을 수있다 가정하자. 괜찮아. 그러나 만일 내가이 이미지와 함께 양쪽 차를 돌려 줄 필요가 있으면 그리고 어떤 이미지도없는 차를 1 개의 목록에 넣어야 할까? 하나의 조건을 두 가지로 통합하려면 어떻게합니까?
django_filters.Filter
?
이 답변은 https://stackoverflow.com/questions/41194200/django-filter-with-drf-how-to-do-and-when-applying-multiple- values-with- 답에서 찾을 수 있습니다. . 당신이 아직도 의심을 가지고 있다면 한번보세요. –