Thursday, 4 January 2024

django model queryset to list (then can use json.dumps to json string). query set to return desired columns only

 https://stackoverflow.com/questions/2448978/how-to-limit-columns-returned-by-django-query

https://stackoverflow.com/questions/16790375/django-object-is-not-json-serializable


list (myqueset.values()) will make queryset to be a list of objects, then .values(columnA) will only return such column


 list(my_queryset.values('first_named_field', 'second_named_field'))


No comments:

Post a Comment