Dinh Truong Anh Phuong
Dinh Truong Anh Phuong

Reputation: 137

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

Upvotes: 0

Views: 100

Answers (1)

Rajat Jog
Rajat Jog

Reputation: 317

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')

Upvotes: 1

Related Questions