Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I tell Django not to load a certain column from the DB

I’m beginning to learn more about improve my app’s performance, and I know while querying I can tell Django to only load the columns I want from the db by using only like the code below:

book = Books.objects.only(“author”, “title”)

What if I want Django to retrieve books but not retrieve the narration column. Please help. Thank you in advance

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I have tried to include all columns except the narration column and that’s too stressful. I believe there should be a way to exclude only one column.

>Solution :

You can use the defer method to tell Django to load every other fields excluding the narration field.

books = Books.objects.defer("narration")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading