Is possible to access the >> request << in .to_internal_value(self, data) ?

8 views
Skip to first unread message

Code Tarsier

unread,
Feb 10, 2016, 11:32:46 PM2/10/16
to Django REST framework
Hi,

According to request.method I want to change dehydrate my data.

e.x.
Psudo Code:

model bookmark:
     title
     desc
     last_operation = [  choice ]

BookmarkSerializer():
    model
    fields

.to_internal_value(self, data)
     if request.get:
           return { title, desc, last_operation=GET  }
     if request.post:
           return { last_operation : "POST", title, desc }
     if request.patch:
           return { last_operation : "PATCH", title, desc }

I know we can achieve this in VIEWSET or Serializer's method. I'm just curious to know whether we can access >> request << in to_internal_value()

thanks in advance.

Code Tarsier

unread,
Feb 11, 2016, 5:27:20 AM2/11/16
to Django REST framework
self.context['request'].method is the answer. 
Reply all
Reply to author
Forward
0 new messages