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 DB
When I only need:
choose items separately from DB
Any way to do it more efficiently?
You
different
section tovalue
or < Want to use in conjunction with code> values_list section?
different
,value
andvalues_list
are 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 to
query.
Comments
Post a Comment