from django.db.models import Q
remove_booking = Q()
for room_id, time_id_list in post_data['DEL'].items():
for time_id in time_id_list:
temp = Q()
temp.connector = 'AND'
temp.children.append(('user_id',2,))
temp.children.append(('date', choice_date))
temp.children.append(('room_id', room_id,))
temp.children.append(('time_id', time_id,))
remove_booking.add(temp, 'OR')
if remove_booking:
models.Book.objects.filter(remove_booking).delete()
add是添加Q对象,children.append是添加条件
示例化Q对象remove_booking = Q()和** temp = Q(),tempQ的参数connector连接关键字“AND"和"OR",默认”AND“, temp.children.append(('user_id',2,))**是添加查询条件以AND链接,('user_id',2,)表示user_id = 2的条件,在把所有temp装入remove列表里以OR链接,