需求:
根据明细表StockQualityOrderLine的 is_new_product
的值筛选出主表的数据.
简要代码如下:
class StockQualityOrderLine(models.Model):
quality_order = models.ForeignKey('warehouse.StockQualityOrder', related_name="StockQualityOrderLine",
on_delete=models.DO_NOTHING,
db_constraint=False)
is_new_product = models.BoolenField()
# filter 设置:
is_new_product = filters.BooleanFilter(field_name='StockQualityOrderLine__is_new_product',label='是否新品',distinct=True)
说明:
- filter 中的
StockQualityOrderLine
代表related_name - 需要添加
distinct=True
选项,否则主表的数据会出现重复
原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/18443.html