Questions tagged [django-rest-viewsets]

362 questions
0
votes
1 answer

Django Rest Framework - Calling .update() from an overriden .create() method inside ModelViewSet

I'm using Django 2.2.x and djangorestframework 3.11.1. Inside a ModelViewSet I had to override the .create() method to customize the default behavior. Sometimes I need to really create a new model instance upon receiving a POST http request,…
0
votes
0 answers

Django REST Framework: Type Error When Trying To Update Using Nested Serializer

I am trying to use a nested serializer in Django Rest Framework. I basically want to update my instance in a single shot. When I send my response, it throws an error saying- save() got an unexpected keyword argument 'id'. I tried popping "id" but…
0
votes
1 answer

Django REST Framework: Exclude a specific route while retain standard ViewSets

I am using Django REST Framework (DRF) for my API. In particular, I have set up several routes using the ModelViewSet, without much additional coding. In particular, I have a route like /api/v1/collection/ From all the possible keys, I do need…
0
votes
1 answer

my django api view.py not showing list and creat new list

Hello developer I'm beginner to django , im following a tutorial in which he create concrete views classes and convert them to viewset.ModelViewSet classes. and he use default router in urls.py my app showing list of articles with viewset but not…
0
votes
1 answer

Access current user from viewsets.ViewSet

I am trying to access current user from List method in viewsets.ViewSet. But I am getting AnonymousUser. I have tried this class ReportViewSet(viewsets.ViewSet): """Shows purchase report group by day""" def list(self, request, **kwargs): …
SAIF AHMED ANIK
  • 735
  • 1
  • 9
  • 19
0
votes
1 answer

Django rest framework creating Orders and order items

I want to create a Order and order items. For this i am simply creating new model object in views.py using CreateApiView but i am receiving error that "Serializer_class" should be included but i don't need serializer for this. //views.py class…
0
votes
1 answer

Django Rest API shows only some urls

I have created a polls app with the Django tutorial and have added a REST API, again with the tutorial. I think I have an error somewhere in my urlpatterns config because I can see only some pages, the rest give me an error. My root url.py: from…
Suki
  • 177
  • 3
  • 12
0
votes
0 answers

How to get and delete access token django api

I want to get access token and delete it in logout api.But i am unable to get access token for the current log in user. models.py class MyUserManager(BaseUserManager): def create_user(self, email, password=None, **extra_fields): if not…
Ashu
  • 1
  • 1
  • 3
0
votes
2 answers

Django Serializer defining initial object

I can't seem to figure out how to pass in an initial value to a serializer. I have a multitenant django site and I am trying to now get APIs setup. The client field exists but needs to be hidden and read only. I thought this worked like a form…
0
votes
0 answers

How to convert an object in django rest framework to a hyperlink

Here is the result of my serializer model "saved_homes": [ { "id": 23, "saved_home": { "home_id": 1, "home_price": 120000, "home_type": "Flat", …
0
votes
1 answer

How do I configure viewsets.ModelViewSet to filter using arguments passed in the body of the request. (Django Rest Framework )

I'm building an API using DJANGO-REST-FRAMEWORK. I'm trying to filter the back end using parameters passed to the body of the request, this is my set up: views.py from .models import UsStatesG from .serializer import UsStatesSerializer from…
0
votes
2 answers

From a django library can we overwrite only parts of a viewset instead of rewriting the viewset completely?

I am working with djoser and upon reading the documentation, I want to alter some parts of the code from Userviewset. I want to overwrite def me(self, request, *args, **kwargs) and customize it. For the get request, instead of returning all the…
0
votes
0 answers

TypeError: save() missing 1 required positional argument: 'self' while using Modelset in DRF

I am facing this error "TypeError: save() missing 1 required positional argument: 'self'" while posting variant to variantgroup using following URL: ../api/v1/variantgroup/1/variant/ Following is my code: Viewsets.py from django.shortcuts import…
Waleed Baig
  • 422
  • 1
  • 6
  • 16
0
votes
0 answers

django rest framework extra actions for routing to specific financial statement of data set

I have a viewset for stocks by ticker/company which corresponds to the urls. localhost:8000/stocks/AAPL works for example. what I want is an extra action to route to localhost:8000/stocks/AAPL/income_statement, but I cant figure out how to create…
Aran Freel
  • 3,085
  • 5
  • 29
  • 42
0
votes
1 answer

How to solve TypeError: create() got an unexpected keyword argument in create function of my view in DRF

I am faced with the problem that I can not successfully receive the kwarg's related with the id of my model Station and as a result I can not create my record through my view in the create function. Despite the fact that I can receive the kwarg's in…