Reputation: 33
i have serialization class like this
class MenuSerializer(serializers.ModelSerializer):
data = Menu.objects.raw('''SELECT menu_menu.*, menu_permission.role_id FROM menu_menu
JOIN menu_permission ON menu_menu.id = menu_permission.menu_id
WHERE sub_menu_id IS NULL
ORDER BY menu_menu.id ASC''')
subItems = SubMenuSerializer(data=data,many=True)
class Meta:
model = Menu
fields = ('id',
'label',
'icon',
'link',
'isTitle',
'isMenuCollapse',
'subItems')
how to filter subItems
based request header
Upvotes: 0
Views: 463
Reputation: 761
This is not the way to go.
Serializers serialize data but don't extract it, you "choose" the data to be shown in the controller ( viewset, in DRF lang ).
Check this https://www.django-rest-framework.org/api-guide/viewsets/
Anyway, you can access the request information using the method "save" in the serializer, it is in the var named "context". You can find it in the documentation too.
Upvotes: 1