Questions tagged [drf-nested-routers]
46 questions
9
votes
3 answers
Django-rest-framework nested urls with drf-nested-routers
I am building nested API with drf-nested-routers package.
However /domains/1/nameservers/ gives me all nameservers I have, not only one related to domain#1
I think the problem is that I use default tutorial NameServerViewSet implementation
class…

Artem Fedosov
- 2,163
- 2
- 18
- 28
8
votes
1 answer
drf-nested-routers RuntimeError('parent registered resource not found')
I am attempting to utilize the package drf-nested-routers to created nested routes within my API.
I've attempted to follow alongside the documentation (https://github.com/alanjds/drf-nested-routers) as well as read through multiple Stackoverflow…

Bonteq
- 777
- 7
- 24
4
votes
1 answer
How to control versioning in Django Rest Framework (DRF)
I want to know what is the best practices for controlling the Version for Mobile App APIs.
Requirement
If I change something in my database previous version of the app should not be affected.
Currently I'm doing like...
path('v1/auth/',…

Sanjay Sikdar
- 435
- 4
- 10
4
votes
1 answer
DRF - Nested Routers - Create/Update nested object on POST/PUT/PATCH
I'm currently starting a simple Task App and I'm using Django 2.0.7, DRF 3.8.2 and drf-nested-routes 0.90.2
I have these models :
class Client(TimeStampedModel):
"""
This model describes a client for the railroader. It can be created by the…

a-coruble
- 411
- 4
- 15
3
votes
1 answer
How can I create an API index using multiple DRF routers?
I'm trying to build an API using DRF with the following structure (example):
api/
├── v1/
│ ├── foo/
│ │ ├── bar/
│ │ │ └── urls.py # There's one `rest_framework.routers.DefaultRouter` here
│ │ ├── bar2/
│ │ │ └── urls.py #…

Gabriel Milan
- 702
- 2
- 7
- 21
3
votes
3 answers
How to get top n rows in django rest framework serializers using serializers relations
I have a serializer that is working fine for all of the data, which is getting from the Database. I want to get top n numbers of rows sorted by some value.
Below is my code in views.py:
@api_view(['GET'])
def org_api(request, org_id):
if…

Huzaifa Zahoor
- 325
- 2
- 13
3
votes
0 answers
How to serialize nested generic relations in django rest frame work
there is a little bit complex model in the project. There are three models bind to each other by generic relations.
Here is the example models:
class Person(models.Model):
first_name = models.CharField()
last_name = models.CharField()
…

Sencer H.
- 1,201
- 1
- 13
- 35
3
votes
1 answer
Using drf-nested-routers with nested HyperlinkedIdentityFields
I am trying to generate nested HATEOAS links in a serializer using the drf-nested-routes package. My current setup would be as…

martinarroyo
- 9,389
- 3
- 38
- 75
3
votes
2 answers
Nested router vs filters
I'm very new to API implementation from ground up and I needed some advice on what the standard or the best approach in my API structure is.
Currently my implementation includes nested routers (drf-nested-routers package) such…

Saumil Patel
- 33
- 2
3
votes
2 answers
How to choose a different serializer class in genericviewsets based on the data sent by the front end
thee are my serializers for different users
class PlayerSerializer(serializers.ModelSerializer):
class Meta:
model = player
fields = ('contact_name', 'contact_email', 'address',)
class…

isaac
- 43
- 1
- 8
3
votes
1 answer
Custom Hyperlinked URL field for more than one lookup field in a serializer of DRF
I am using Django Rest Framework for developing web api for my project. As in my project i need to build nested api's endpoint like this:
/users/ - to get all users
/users/ - to get details of a particular user
…

Akshay Pratap Singh
- 3,197
- 1
- 24
- 33
2
votes
1 answer
How to include Hyperlinks for nested resources in drf-nested-routers to apply HATEOAS principle?
Context
I have an API in Django REST framework with the following nested…

Santiago Ortiz Ceballos
- 152
- 2
- 7
2
votes
1 answer
What is "lookup" argument of NestedSimpleRouter class?
I'm using drf-nested-routers to create several nested API endpoints.
Let's take a look at the next piece of code in my routes.py file:
from rest_framework_nested.routers import SimpleRouter, NestedSimpleRoute
base_router =…

curioushuman
- 207
- 3
- 11
2
votes
1 answer
NestedSimpleRouter without using lookup in router
I am using drf-nested-router something like the following in my url.py
router = SimpleRouter()
profile_router = routers.NestedSimpleRouter(router, r'profile', lookup='user')
profile_router.register(r'comments', UserCommentViewSet,…

sadat
- 4,004
- 2
- 29
- 49
2
votes
1 answer
can't use reverse url function in django
tests.py
from django.test import TestCase
from django.urls import reverse
from rest_framework import status
from .models import User
class UserCreateAPIViewTestCase(APITestCase):
def setUp(self):
super().setUp()
self.url =…

Vu Tran
- 25
- 5