'Limited some column in queryset django
I tried many ways but all failed when trying to get some special columns in model.
My code:
or I use defer
test_detail=testimport.objects.defer("so_hd","noi_dung")
or I use only
test_detail=testimport.objects.only("so_hd","noi_dung")
or even use filter and defer/only
test_detail=testimport.objects.filters().def("so_hd","noi_dung")
When I print print(test_detail.values("ten_kh")), there are still results.
Because there are some columns I rarely use, so I want to save memory and improve speed if don't get there columns
Please help me
Solution 1:[1]
I think you might want to select specific columns of a table:
for this you need to use:
data = Model.objects.values('column_1', 'column_2')
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Rajat Jog |
