Django: using values() and get_FOO_display()?

后端 未结 2 2046
孤街浪徒
孤街浪徒 2021-01-12 01:43

I\'m trying to improve some existing code which originally took 3 minutes to prepare a large dataTable (then returned by Ajax). The old code iterated over a large querySet,

2条回答
  •  北恋
    北恋 (楼主)
    2021-01-12 02:07

    iterating over querysets is generally a bad idea, because SQL is executed for each item

    That's not true. Below is taken from the official docs:

    A QuerySet is iterable, and it executes its database query the first time you iterate over it

    I think the problem has to do with the definition of the users from your code. What did you assign to it?

提交回复
热议问题