Skip to content

Instantly share code, notes, and snippets.

@mitshel
Created November 9, 2018 07:57
Show Gist options
  • Save mitshel/c45cdccba8165de0f502369b9a535b58 to your computer and use it in GitHub Desktop.
Save mitshel/c45cdccba8165de0f502369b9a535b58 to your computer and use it in GitHub Desktop.
Dhango QuerySet to List
# Преобразует 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