1👍
✅
You mean get_queryset
and it’s not a serializer method, it’s a view set method. Thus, you’ll have something like:
class OfferViewSet(viewsets.ModelViewSet):
serializer_class = OfferSerializer
def get_queryset(self):
return Offer.objects.filter(item_given__owner=self.request.user)
0👍
I couldn’t solve the form displaying every items but I could make it raise an error if the item is not owned by the user
def validate(self, data):
if self.context['request'].user.userprofile != data['item_given'].owner:
raise serializers.ValidationError("Item given is not owned by the current user")
return data
- Setting model user to current user when using inlineformset_factory in Django
- Django download generated file
Source:stackexchange.com