MattBroach / DjangoRestMultipleModels

View (and mixin) for serializing multiple models or querysets in Django Rest Framework
MIT License
549 stars 67 forks source link

Is it possible to send context with the querylist? #49

Open asbin143 opened 4 years ago

asbin143 commented 4 years ago

Actually i want to send extra argument with the serializer. Eg. serializer = PollDetailSerializer(context={"user_id": request.user.user_id})

Naveenkorkopp commented 3 years ago

@asbin143

I too had this requirement using this package. There is a way to override the get_serializer_context method just like this

def get_serializer_context(self):
    context = super(CLASS_VIEWSET_NAME, self).get_serializer_context()
    context.update({"user_id": self.request.user.user_id})
    return context