1👍
✅
Since I am on the deadline, I reverted to run queries directly and converted as a list of dicts and returned from my list method of viewset like this:
desc = cursor.description
result = [
dict(zip([col[0] for col in desc], row))
for row in cursor.fetchall()
]
return Response(result)
It still uses the Django Rest API interface so its not a big deal for me to have some occasional hard coded sql queries.
But I would appreciate if Django Rest Framework 3.x being flexible to handle this kinda use cases.
👤Jega
0👍
So, given your SQL query, it seems like the classroominfo
table is at the center of some kind of star schema. You should be able to use the “depth” attribute to include nested serializations.
class ClassroominfoSerializer(serializers.ModelSerializer):
class Meta:
model = models.Classroominfo
fields = ('classroomid', 'assessmentid','resourceid', 'writtenworkid')
depth = 2
- [Answer]-Unable to access static files with NGINX, gunicorn and Django
- [Answer]-Tracking anonymous users in Angular app
- [Answer]-Django: exclude User list from all Users
- [Answer]-Django Tincymce, AttributeError: 'NoneType' object has no attribute 'endswith'
Source:stackexchange.com