Skip to content
Gallery
DB App-Eat-Easier v3.0
Share
Explore
Code Snippets

icon picker
Django Snippet

Trying to combine 2 or more models / serializers in one view
class UserProfileDetailAPIView(generics.ListAPIView):
"""
This view its purpose its to retrieve full user profile including preferences
"""
queryset = UserProfile.objects.all()
serializer_class = UserProfileSerializer
def get_queryset1(self):
user_profile = self.kwargs['pk']
filter = {}
if user_profile:
filter['user_profile'] = user_profile
return UserProfile.objects.filter(**filter)
def get_serializer_class1(self):
return UserProfileSerializer(self.get_queryset1(), many=True)
def list(self, request, *args, **kwargs):
serializer1 = self.get_serializer_class1()
return Response(serializer1.data)

This class its going to have the same function as UserProfileRecipeSerializer
class UserFavoritesListSerializer(serializers.ModelSerializer):
"""
This serializer its purpose is to give the List of User´s Favorites Recipes
"""
class Meta:
model = UserRecipe
fields = ['']


Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.