2015-05-03 23 views

Odpowiedz

4

Nie można, values można pobrać wartości przechowywane w bazie danych, reprezentacja ciąg jest nie tylko przechowywane w bazie danych, jest ona obliczana w Pythonie.

Co można zrobić, to:

qs = User.objects.all() 
# Compute the values list "manually". 
data = [{'id': user.id, '__str__': str(user)} for user in qs] 

# You may use a generator to not store the whole data in memory, 
# it may make sense or not depending on the use you make 
# of the data afterward. 
data = ({'id': user.id, '__str__': str(user)} for user in qs) 

Edit: na drugim myśli, w zależności od sposobu reprezentacji ciąg jest obliczane, może to być możliwe użycie annotate z query expressions aby osiągnąć ten sam rezultat.

Powiązane problemy