Created
November 9, 2018 07:57
-
-
Save mitshel/c45cdccba8165de0f502369b9a535b58 to your computer and use it in GitHub Desktop.
Dhango QuerySet to List
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Преобразует Django QuerySet в список | |
# поонадобилось в связи с использованием RAW запросов | |
def to_list(qs): | |
mlist = list() | |
for row in qs: | |
d = {} | |
for f in qs.columns: | |
d[f] = getattr(row, f) | |
mlist.append(d) | |
return mlist |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment