我很难实现或使用Django过滤器的查询。我可以找到some example telling how to create OR query in django queryset。但是,我无法在django-filter文档中找到。有谁知道如何使用django-filter来实现OR查询吗? model.py和filter.py如下所示。或在Django过滤器中的查询
model.py
class html(models.Model):
project = models.CharField(max_length=50, blank=True)
version = models.IntegerField(default=0)
ecms=models.ManyToManyField(ecm, blank=True)
diff = models.TextField(blank=True)
PROGRAM_CHOICES = (
('Office', 'General office'),
('Residential', 'Residential'),
('Retail', 'Retail'),
('Restaurant', 'Restaurant'),
('Grocery', 'Grocery store'),
('Medilcal', 'Medilcal office'),
('Research', 'R&D or laboratory'),
('Hotel', 'Hotel'),
('Daycare', 'Daycare'),
('K-12', 'Educational,K-12'),
('Postsecondary', 'Educational,postsecondary'),
('Airport', 'Airport'),
('DataCenter','Data Center'),
('DistributionCenter','Distribution center,warehouse')
)
program = models.CharField(max_length=20, choices=PROGRAM_CHOICES, default='Retail')
LOCATION_CHOICES = (
('Beijing', 'Beijing'),
('China', 'China'),
('Hong Kong', 'Hong Kong'),
('Japan', 'Japan'),
('Shanghai', 'Shanghai'),
('Shenzhen', 'Shenzhen'),
('Taiwan', 'Taiwan')
)
location = models.CharField(max_length=15, choices=LOCATION_CHOICES, default="Hong Kong")
CERTIFICATE_CHOICES = (
('LEED_v3', 'LEED_v3'),
('LEED_v4', 'LEED_v4'),
('BEAM+', 'BEAM+'),
('WELL', 'WELL')
)
certificate = models.CharField(max_length=10, choices=CERTIFICATE_CHOICES, default='BEAM+')
user = models.CharField(max_length=20, default='test')
html = models.FileField(upload_to=dir_path)
uploaded_at = models.DateTimeField(auto_now_add=True)
filter.py
import django_filters
from .models import html
class ProjectFilter(django_filters.FilterSet):
class Meta:
model=html
fields=['project','program','location','certificate','user']