diff --git a/docs/cookbook.rst b/docs/cookbook.rst index be41f7cbd..e6fe85dea 100644 --- a/docs/cookbook.rst +++ b/docs/cookbook.rst @@ -71,7 +71,7 @@ provide additional values: class Meta: queryset = MyModel.objects.all() - def dehydrate(self, bundle): + def dehydrate(self, bundle, **kwargs): bundle.data['custom_field'] = "Whatever you want" return bundle diff --git a/docs/resources.rst b/docs/resources.rst index 0811db663..a2cdf4fa7 100644 --- a/docs/resources.rst +++ b/docs/resources.rst @@ -288,7 +288,7 @@ A simple example:: class Meta: queryset = Note.objects.all() - def dehydrate(self, bundle): + def dehydrate(self, bundle, **kwargs): # Include the request IP in the bundle. bundle.data['request_ip'] = bundle.request.META.get('REMOTE_ADDR') return bundle @@ -300,7 +300,7 @@ A complex example:: queryset = User.objects.all() excludes = ['email', 'password', 'is_staff', 'is_superuser'] - def dehydrate(self, bundle): + def dehydrate(self, bundle, **kwargs): # If they're requesting their own record, add in their email address. if bundle.request.user.pk == bundle.obj.pk: # Note that there isn't an ``email`` field on the ``Resource``. @@ -1121,7 +1121,7 @@ simply override this method. ``full_dehydrate`` ------------------ -.. method:: Resource.full_dehydrate(self, bundle, for_list=False) +.. method:: Resource.full_dehydrate(self, bundle, for_list=False, for_update=False) Populate the bundle's :attr:`data` attribute. @@ -1133,6 +1133,11 @@ The ``for_list`` parameter indicates the style of response being prepared: be called once for each object requested. - ``False`` indicates a response showing the details for an item +The ``for_update`` parameter indicates this operation is for a PATCH request; + - ``True`` indicates this is a PATCH, so fields loaded from the db should not be + modified for external consumption (e.g. a url prepended for images) + - ``False`` indicates a normal dehrydate operation + This method is responsible for invoking the the :meth:`dehydrate` method of all the fields in the resource. Additionally, it calls :meth:`Resource.dehydrate`. @@ -1145,7 +1150,7 @@ and return it, but you may also return a completely new bundle. ``dehydrate`` ------------- -.. method:: Resource.dehydrate(self, bundle) +.. method:: Resource.dehydrate(self, bundle, for_list=False, for_update=False) A hook to allow a final manipulation of data once all fields/methods have built out the dehydrated data.