# Accessing specific fields with Rest Framework ViewSets

**URL:** <https://forum.djangoproject.com/t/accessing-specific-fields-with-rest-framework-viewsets/15033>\
**Category:** Forms & APIs\
**Created:** [July 25, 2022, 9:42pm UTC](https://forum.djangoproject.com/t/accessing-specific-fields-with-rest-framework-viewsets/15033 "2022-07-25T21:42:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sergei-p](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/sergei-p/32/9432_2.png) [@sergei-p](https://forum.djangoproject.com/u/sergei-p)\
**Post date:** [July 25, 2022, 9:42pm UTC](https://forum.djangoproject.com/t/accessing-specific-fields-with-rest-framework-viewsets/15033/1 "2022-07-25T21:42:54Z")

</div>

Hi,

I am new to the Django Rest Framework and have been recently introduced to Viewsets. I understand that Viewsets provide prebuilt classes for handling commonly used CRUD operations. This in turn allows developers to configure their views a lot more quickly and efficiently by simply initializing a couple of variables in their View Classes. Form what I have understood so far is that, for example, if we are using a ReadOnlyModelViewSet, then our class will automatically generate endpoints for GET requests. And by default, if we wish to perform a GET operation where we would like to retrieve a specific row from our table, then the ModelViewSet will use the DB models pk to do so. My question is this. What if I would like to access a db column with a field other than the pk. Would I have to override a default pre-existing ReadOnlyModelViewSet method to do so?

---

<div class="post-metadata">

**Author:** ![leandrodesouzadev](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/leandrodesouzadev/32/8981_2.png) [@leandrodesouzadev](https://forum.djangoproject.com/u/leandrodesouzadev)\
**Post date:** [July 26, 2022, 10:12am UTC](https://forum.djangoproject.com/t/accessing-specific-fields-with-rest-framework-viewsets/15033/2 "2022-07-26T10:12:38Z")

</div>

Hey there!

> [@sergei-p](#):
>
> What if I would like to access a db column with a field other than the pk

I think that what you mean from this is related with `lookup_field`, [docs](https://www.django-rest-framework.org/api-guide/generic-views/#attributes).  
You can set it on your viewset.  
Take into account that this can have perfomance implications on a bid dataset if you filter from a db column not indexed.

---

<div class="post-metadata">

**Author:** ![sergei-p](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/sergei-p/32/9432_2.png) [@sergei-p](https://forum.djangoproject.com/u/sergei-p)\
**Post date:** [July 26, 2022, 3:16pm UTC](https://forum.djangoproject.com/t/accessing-specific-fields-with-rest-framework-viewsets/15033/3 "2022-07-26T15:16:22Z")

</div>

Thank you for the response!
