“Django valores_list” Código de respuesta

¿Qué es valores_list en 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

Django Qeryset Count

# 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 en 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

Respuestas similares a “Django valores_list”

Preguntas similares a “Django valores_list”

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código