JavaScript required
We’re sorry, but Coda doesn’t work properly without JavaScript enabled.
Skip to content
Gallery
DB App-Eat-Easier v3.0
App-Eat-Easier
More
Share
Explore
Code Snippets
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 (
Ctrl
P
) instead.