Multiple lookup_fields for django rest framework
<p>I have multiple API which historically work using <code>id</code> as the lookup field:</p>
<pre><code>/api/organization/10
</code></pre>
<p>I have a frontend consuming those api.</p>
<p>I'm building a new interface and for some reasons, I would like to use a slug instead an id:</p>
<pre><code>/api/organization/my-orga
</code></pre>
<p>The API is built with Django Rest Framework. Except the change of lookup field, the api behavior should stay the same.</p>
<p>Is there a solution to allow my API to work with both a <code>slug</code> and a <code>pk</code> ? Those two path should give them same results:</p>
<pre><code>/api/organization/10
/api/organization/my-orga
</code></pre>
<p>Here is my API definition:</p>
<pre><code># urls.py
router = DefaultRouter()
router.register(r'organization', Organization)
urlpatterns = router.urls

#view.py
class Organization(viewsets.ModelViewSet):
    queryset = OrganisationGroup.objects.all()
    serializer_class = OrganizationSerializer

# serializer.py
class OrganizationSerializer(PermissionsSerializer):
    class Meta:
        model = Organization
</code></pre>