# Editing serialized viewsets response to include additional value, and overriding viewset response?

**URL:** <https://forum.djangoproject.com/t/editing-serialized-viewsets-response-to-include-additional-value-and-overriding-viewset-response/20646>\
**Category:** Forms & APIs\
**Created:** [May 1, 2023, 3:04am UTC](https://forum.djangoproject.com/t/editing-serialized-viewsets-response-to-include-additional-value-and-overriding-viewset-response/20646 "2023-05-01T03:04:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![chrisjdixon](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/chrisjdixon/32/6463_2.png) [@chrisjdixon](https://forum.djangoproject.com/u/chrisjdixon)\
**Post date:** [May 1, 2023, 3:04am UTC](https://forum.djangoproject.com/t/editing-serialized-viewsets-response-to-include-additional-value-and-overriding-viewset-response/20646/1 "2023-05-01T03:04:42Z")

</div>

[Asked over at SO](https://stackoverflow.com/q/76134340), we’re trying to include an additional value in our responses that JS can use alongside the original response which is used as a geojson. Please see question for full context.

Someone pointed out responses can be adjusted in views.py, which makes total sense, except we’re using viewsets.py, as adapted from @pauloxnet’s [great map tutorial](https://www.paulox.net/2021/07/19/maps-with-django-part-2-geodjango-postgis-and-leaflet/#adding-the-marker-viewset). We thought we should try to override the `MarkerViewSet(viewsets.ReadOnlyModelViewSet)` response [as discussed here](https://stackoverflow.com/a/55147701), but `retrieve()` doesn’t seem to do anything. What we hoped might work:

```py
class MarkerViewSet(viewsets.ReadOnlyModelViewSet):
    bbox_filter_field = "location"
    filter_backends = (filters.InBBoxFilter,)
    queryset = Marker.objects.all()
    serializer_class = MarkerSerializer

    def retrieve(self, queryset, request, *args, **kwargs):
        print("retrieve method was used") # not being printed
        return({'new_value': "foo", 'geojson': queryset})

```

Are we going about this the right way? How can we just include another value that JS can access with something like `newResponse.new_value` and existing functionality can continue getting the same data via `newResponse.geojson` or similar?

Thanks for any help!

---

<div class="post-metadata">

**Author:** ![chrisjdixon](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/chrisjdixon/32/6463_2.png) [@chrisjdixon](https://forum.djangoproject.com/u/chrisjdixon)\
**Post date:** [May 2, 2023, 9:13pm UTC](https://forum.djangoproject.com/t/editing-serialized-viewsets-response-to-include-additional-value-and-overriding-viewset-response/20646/2 "2023-05-02T21:13:46Z")

</div>

After a few days of going insane I figured it out with some help from a much better programmer. Please see [updated SO thread](https://stackoverflow.com/a/76158908). Thanks anyway!

---

<div class="post-metadata">

**Author:** ![pauloxnet](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/pauloxnet/32/11021_2.png) [@pauloxnet](https://forum.djangoproject.com/u/pauloxnet)\
**Post date:** [May 5, 2023, 10:49pm UTC](https://forum.djangoproject.com/t/editing-serialized-viewsets-response-to-include-additional-value-and-overriding-viewset-response/20646/3 "2023-05-05T22:49:12Z")

</div>

I’m happy that you found my web map article series useful 🙏
