0
我有包含用戶對象作爲外鍵的模型。 雖然我在Django admin上展示它,但它會爲模型的每一行選擇所有用戶對象(它會在下拉菜單中顯示它們)。django admin - 每行選擇用戶對象 - 性能低
如何才能使用戶對象的一個選擇,然後將其用於所有行?
查詢:
SELECT ••• FROM "users_user" ORDER BY "users_user"."email" ASC
SELECT ••• FROM "users_user" ORDER BY "users_user"."email" ASC
SELECT ••• FROM "users_user" ORDER BY "users_user"."email" ASC
SELECT ••• FROM "users_user" ORDER BY "users_user"."email" ASC
SELECT ••• FROM "users_user" ORDER BY "users_user"."email" ASC
SELECT ••• FROM "users_user" ORDER BY "users_user"."email" ASC
SELECT ••• FROM "users_user" ORDER BY "users_user"."email" ASC
SELECT ••• FROM "users_user" ORDER BY "users_user"."email" ASC
SELECT ••• FROM "users_user" ORDER BY "users_user"."email" ASC
我的管理模型:
class RoleAdmin(admin.TabularInline):
model = Role
fields = ('user', 'role_type', 'is_active',)
extra = 0
*編輯:
我試圖添加以下代碼,但它沒有任何意義:
def queryset(self, request):
return super(RoleAdmin, self).queryset(request).select_related('user')
*更新:
我嘗試設置raw_ids_fields,但它仍然無效,因爲它不會在角色和用戶之間進行內部連接,而是分別爲每個用戶查詢。
它仍然是無效的。它爲每個用戶選擇查詢,而不是角色和用戶之間的內部聯接。 – Nimi
請用你試過的東西和輸出來更新你的問題。 –