簡體   English   中英

將原始查詢轉換為 django orm

[英]Convert raw 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));

這可能會幫助你

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

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM