简体   繁体   English

将原始查询转换为 django orm

[英]Convert raw query to django orm

I written this query in MySQL and I'm confused of conversion of this query to django orm我在 MySQL 中编写了此查询,但我对将此查询转换为 django orm 感到困惑

SELECT * FROM student.student_data 
where created_by in (select user_id from user_profile where user_location in(7, 8));

This might help you这可能会帮助你

query = UserProfile.objects.filter(user_location__in = [7,8])
student_data = Student.objects.filter(created_by = query)

For more: [https://mattrobenolt.com/the-django-orm-and-subqueries/]更多信息:[https://mattrobenolt.com/the-django-orm-and-subqueries/]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM