我想使用一個Django模型來記錄,但然後返回一個外鍵連接的兩個不同表的連接字段。Django模型搜索連接字符串
我能做到這一點在SQL這樣的:
SELECT
location.location_geoname_id as id,
CONCAT_WS(', ', location.location_name, region.region_name, country.country_name) AS 'text'
FROM
geonames_location as location
JOIN
geonames_region as region
ON
location.region_geoname_id = region.region_geoname_id
JOIN
geonames_country as country
ON
region.country_geoname_id = country.country_geoname_id
WHERE
location.location_name like 'location'
ORDER BY
location.location_name, region.region_name, country.country_name
LIMIT 10;
有一個更清潔的方式做到這一點使用Django模型?或者我需要爲這個使用SQL嗎?
謝謝