“Django valores_list” Respostas de código

O que é valores_list em Django Orm

 Test.objects.all()                                  time: 0.010061947107315063
 Test.objects.all().values('first')                  time: 0.00578328013420105
 Test.objects.all().values_list('first')             time: 0.005257354974746704
 Test.objects.all().values_list('first', flat=True)  time: 0.0052023959159851075
 Test.objects.all().only('first')                    time: 0.011166254281997681
Enthusiastic Elephant

Contagem de consultas de Django

# Returns the total number of entries in the database.
count = Entry.objects.count()

# Returns the number of entries whose headline contains 'Lennon'
count = Entry.objects.filter(headline__contains='Lennon').count()
Repulsive Raven

Lista de valores em Django

>>> qs1 = Author.objects.values_list('name')
>>> qs2 = Entry.objects.values_list('headline')
>>> qs1.union(qs2).order_by('name')
biswajit

django valores_list

>>> list(Article.objects.values_list('id', flat=True)) # flat=True will remove the tuples and return the list   
[1, 2, 3, 4, 5, 6]

>>> list(Article.objects.values('id'))
[{'id':1}, {'id':2}, {'id':3}, {'id':4}, {'id':5}, {'id':6}]
Blessed Sam

Django valores_list

Cannot resolve keyword 'lyrics' into field. Choices are: id, song, song_id
Annoying Ape

Respostas semelhantes a “Django valores_list”

Perguntas semelhantes a “Django valores_list”

Procure respostas de código populares por idioma

Procurar outros idiomas de código