sql - Distinct elements in django model -
I am a Django novice and I wonder if there is a more efficient way to do the following tasks (at the database level) .
I have a model:
class.fu (models.Model): item = model.Intergrill () another_item = models.IntegerField ()and want to get all the different values of "item".
It is that I have done so far:
distinct = set (for row in [Row.item Foo.objects.all ()))It's easy to understand But if I understand how Django works then the SQL query is not very efficient because it is something like this:
SELECT * FROM DBWhen I only need:
choose items separately from DBAny way to do it more efficiently?
You
differentsection tovalueor < Want to use in conjunction with code> values_list section?
different,valueandvalues_listare all there.Then you can do this:
Foo.objects.values_list ('item', flat = true)and It will return a list of items - match your
match to a different item related toquery.
Comments
Post a Comment