简体   繁体   中英

How to fetch data while ignoring some specific fields?

With a model Book that uses MarkDown for a field called content , when I do the following query

Book.objects.filter(published=True).order_by('read')

The site becomes slow because of the content field, I think the hard work occurs when Django tries to convert these fields to python object . When I clean all the content field for each record and leave them blank, the query is pretty much faster.

In my case content field contains large text. To gain in performance, How can I fetch data by ignoring a specific field?

I want to ignore content field like:

Book.objects.filter(published=True).order_by('read')

尝试使用defer

Book.objects.defer('content').filter(published=True).order_by('read')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM