django - Add context to head of ListAPIView -


i add {'user': self.request.user} header of listapiview.

for example, json response like:

[     'user': testing_user,     {         id: 67,         slug: "slugy",     }, ] 

is possible this view?

class bookarchiveapiview(generics.listapiview):     cache_timeout = 60 * 7     serializer_class = bookserializer     queryset = book.objects.all() 

i know late needed same thing , found on documentation easily.

you don't need pass "request.user" view because drf gives you.

here example:

class show_activities(generics.listapiview): serializer_class = activityserializer  def get_queryset(self):     username = self.request.user.username     return activity.objects.filter(owner=username) 

it's easy find on documentation i'm answering ones couldn't see it.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -