Questions tagged [django-rest-viewsets]

362 questions
4
votes
4 answers

'collections.OrderedDict' object has no attribute 'pk' - django rest framework

I have a model and I want to write an update() method for it in order to update. The below snippet is my model: class Klass(models.Model): title = models.CharField(max_length=50) description = models.CharField(max_length=500) university…
4
votes
0 answers

Custom comments for viewset in api documentation

I have django rest framework api application and generate documentation for it. I use api view with viewset and I have custom method. In urls I use routers. For generate documentation I use DRF Docs. My view: class…
SmoQ
  • 293
  • 2
  • 10
3
votes
1 answer

how to pass extra parameter to django rest custom action inside the viewset?

@action(detail=True, methods=['get'], url_path='password-reset//', url_name='password-reset-confirm') def password_reset(self, request, uid64, token): pass this is the url (…
3
votes
1 answer

Setting up simple Django ViewSet APIs from multiple apps

I’m still learning django and assume this may be easy for some. I’m trying to figure out the best way of simply setting up the API URLs (and so that they all display in the api root and can actually be used in the project - in my case at /api/). I’m…
user8758206
  • 2,106
  • 4
  • 22
  • 45
3
votes
1 answer

DRF: router for ViewSet with a foreign-key lookup_field

Using Django REST Framework 3.12.4, I cannot properly get the URLs for a ViewSet to work if that ViewSet has a foreign-key lookup field. I have the following in models.py: class Domain(models.Model): name = models.CharField(max_length=191,…
3
votes
2 answers

Django Rest Framework Filtering an object in get_queryset method

Basically, I have a catalog viewset. In the list view I want to make a few filtering and return accordingly. Relevant Catalog model fields are: class Catalog(models.Model): name = models.CharField(max_length=191, null=True, blank=False) ... …
3
votes
3 answers

Django Rest Framework custom permission not working

I want users to have access only to the records that belong to them, not to any other users' records so I've created the following view: class AddressViewSet(viewsets.ModelViewSet): authentication_classes = (TokenAuthentication,) …
3
votes
2 answers

DRF how can I return only the first serialized object to the view?

in DRF, is there any way to get a single nested image to show up in a view. In my example you can see that there are 2 photos listed. What would be the best solution to retrieve and display just that first photo? This view would be for a list of…
master_j02
  • 377
  • 3
  • 13
3
votes
2 answers

Django REST Framework TypeError: register() missing 1 required positional argument: 'viewset'

Im learning Django REST Framework and Im trying to get to work a simple ViewSet but I keep getting this error on the console when trying to run the server File "C:\Users\anahu\Projects\guatudu-api\api\api\locations\urls.py", line 13, in
Anibal Cardozo
  • 479
  • 1
  • 10
  • 21
3
votes
2 answers

missing 1 required positional argument: 'request' django restframework

I was using routers for creating urls now i want to make urls for my api, but problem is, i am getting error createuser() missing 1 required positional argument: 'request'missing 1 required positional argument: 'request' iam getting same error…
Vikas Gautam
  • 239
  • 1
  • 4
  • 21
3
votes
1 answer

how to set authentication and permission only on PUT requests in django REST in viewsets?

I have a viewset subclassing from modelviewset, I add next: authication_classes = [SessionAuthentication,BasicAuthentication] permission_classes = [IsAuthenticated] Then, got following message when list, detail/retrieve and put requests. "detail":…
3
votes
2 answers

Django rest framwork: DELETE without pk

I user Django Rest Framwork. I want to make a api for delete an object like this DELETE .../items/ to delete request.user's item. (Each user can create at most one item only, and only owner can delete his item.) I use mixins.CreateModelMixin,…
3
votes
1 answer

Django rest framework router not found

In my application I'm using ModelViewSet, as for urls I used SimpleRouter(): main.urls urlpatterns = [ url(r'^teams/', include('team.urls', namespace='teams')), ] team.urls router = SimpleRouter() router.register('', views.TeamViewSet,…
alex
  • 2,381
  • 4
  • 23
  • 49
3
votes
0 answers

Django rest framework: searching on annotated field using ModelViewSet

how are you? :) My question is about using django RF ViewSets, RF Filters, over annotated fields with custom Object Managers. So I've got this class class SomeClass(models.Model): this_does_not_matter = models.CharField(max_length=50) …
3
votes
1 answer

django rest framework viewset permission based on method

So I'm writing my first project with DRF and I'm having some issues with setting up permissions for my viewsets. I already have authentication working with djangorestframework-jwt. Currently, I have a few different ViewSets defined. What I would…
1 2
3
24 25