1👍
✅
You add the data of the brand with it, with .select_related(…)
[Django-doc] so:
@api_view(['GET'])
def autofill_api(request):
items = Product.objects.select_related('brand')
serializer = AutoFillSerializer(items, many=True)
return Response(serializer.data)
Note: Especially for Django REST API views, it is better to work with class-based views since it can automate a lot, like injecting a context in the serializer, easily checking (object)permissions. While one can work with a function-based view, it often does not pay off to do so, especially for "basic scenario" views.
Source:stackexchange.com