我现在使用 django 过滤器来获取我想要的查询集,这是我的代码:
students = Student.objects.filter(
sales=current_user,
nickname = form_data['nickname'],
mobile = form_data['mobile'],
gender = form_data['gender'],
state = form_data['state'],
source = form_data['source'],
register_at = form_data['register_at'],
importance = form_data['importance'],
remaining = form_data['remaining'],
level = form_data['level'],
feature = form_data['feature'],
company_name = form_data['company']
).order_by(register_order, remaining_order, level_order)
现在的问题是:我的一些表单数据字段可能为空,因为表单是用户输入的,他/她可以选择只输入一些字段,我想知道当某些字段为空时这段代码是否可以工作,如果不是,如何重写它以根据用户输入的字段获取查询集?