Questions tagged [django-rest-framework]

A powerful and flexible toolkit for building RESTful Web APIs. Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design. Built by experienced developers, it takes care of much of the hassle of Web development, so you can focus on writing your app without needing to reinvent the wheel. It’s free and open source.

0
votes
2answers
34 views

I can't multiply two fields. Error: invalid literal for int() with base 10:

I try to multiply price and quantity. but somethings went wrong. 'quantity' and 'price' both is IntegerField() class BillListSum(generics.GenericAPIView): def get(self, request): bill = ...
0
votes
2answers
14 views

How to pass the dictonary object to Django-rest-framework with double quote by http.request's json parameter?

I got this error message on Django-rest-framework. JSON parse error - Expecting property name enclosed in double quotes: line 1 column 2 (char 1)" } Its cause must be single quote, but I passed the ...
0
votes
2answers
28 views

django-rest: TypeError: unhashable type: 'list'

I am trying to restify my backend using django-rest-gis, in such a way that POST request adds data to database and GET request lists down the data. However, I am getting following error:- Internal ...
0
votes
1answer
10 views

Django RestFramework - parent-child model serializer with DB views?

I am trying to implement a serializer that returns a parent record with its children embedded in the response json object. My model for the parent and child are both based on database views: class ...
0
votes
1answer
24 views

Serializing Foreign Key Field

I have the following models: class Question(models.Model): test = models.ForeignKey(Test, on_delete=models.CASCADE) text = models.CharField(max_length=255,default='',blank=False) number = ...
0
votes
0answers
9 views

Django Rest API: how can I call a model inside a model?

I want to follow django rest framework. And create an API which has an url like 'electronics/1/stock/' where electronics and stock both are models in django admin.
0
votes
1answer
10 views

How to update response from external api in DRF

I am dealing with an assignment, which needs to request a third party API and take a few bites of the response and update their keys and render as DRF response. Can this be achieved via serializers? ...
0
votes
0answers
12 views

Add permission from Django rest framework to function base view

I want response a simple Json when clint have permission. (I don't want retrieve model instance). It will be better if you can offer class-base view from restframework (generic or APIView or Viewset ...
0
votes
1answer
22 views

Error while inserting values in to database

When I try to put values in to databse, I am getting this error. raise TypeError("%s() got an unexpected keyword argument '%s'" % (cls.name, kwarg)) TypeError: Employee() got an unexpected ...
0
votes
0answers
13 views

POST 400 Bad request

I am new to django and reactjs and I am trying to POST request using axios but I am unable to send data. I am getting console error POST http://localhost:8000/api/todos/ 400 (Bad Request) this is my ...
0
votes
0answers
5 views

How to filter out all Upsertable entities in successfactors using postman?

I am learning about SuccessFactors employee central API's. I want to upsert entities using postman. But I cannot find any resource about how to filter out all entities which can be upserted. Is there ...
0
votes
0answers
16 views

Permission error with Classview extending ViewSet, how can I add permissions to non model viewset?

I am trying to create a set of endpoints that are not related to models in Django. I am using Oauth2 for authentification and I am getting all the time 403 error asking for missing permissions. How ...
-1
votes
0answers
5 views

Global dictionary for each request

I want to use an uuid in my API to identify the request for a log implementation, there is any tool for it ?? I look up into the DRF documentation but i did not found anything
-1
votes
1answer
18 views

how can use custom permission djangorestframework

I have a project and now i want add a my new endpoint to this project that response a json . this json is very simple and not need to any serializer or queryset.but i dont know how i can use ...
0
votes
1answer
26 views

Django doesn't convert the datetime using the right timezone

I'm struggling to figure out how timezone works in Django. On my systems I have all datetimes in UTC+00 even with a UTC+02 TIME_ZONE setting. timezone.get_default_timezone() ...
0
votes
1answer
33 views

TypeError: 'F' object is not subscriptable

I am using Django ORM to query a database called Product having column name price(Decimal) and stock_units(int). I want to Multiply both of the columns and get the accumulated summation. report = ...
0
votes
1answer
23 views

How to add a django rest framework authentication in Route?

How to add a django rest framework authentication in Route? I am using JWT for authentication of my application. Everything works perfectly. What I need to know is how can I authenticate a ...
0
votes
1answer
32 views

django) request.POST method gives me errror : querydict object is not callable

I'm trying to add social login to my django-rest-framework app, but I'm stuck on this problem and need some help. Login Flow: Request code(GET) -> Response -> Request token(POST)(This part is where I'...
0
votes
1answer
22 views

Steps for Creating Login api using django rest framework by Token Authentication

I am trying to create login api with LoginSerializer and LoginAPIView using django-rest-auth, can anyone please explain the steps on how to do it?
0
votes
0answers
20 views

filling two table with one post request

I have a model that stores a text. I have another related model that is supposed to store the entities in the first model. For example suppose I am posting a text like "France is in Europe", which ...
0
votes
0answers
20 views

Data in table is not updated from django-rest-framework UpdateAPIView?

This is my update api view: class CountlUpdateView(UpdateAPIView): serializer_class = CountSerializers def get_queryset(self, *args, **kwargs): id = self.kwargs.get('pk') ...
0
votes
1answer
17 views

Django Rest Framework Request Validation

Is there a way to validate params that are passed with the request without writing boilerplate code? Now I've got something like this: project_id = kwargs['project_id'] try: ...
2
votes
1answer
13 views

ImportError: cannot import name 'DjangoFilterBackend'

After upgrading to Django REST framework 3.7 I got following error File "/home/jpg/Projects/django2x/sample/views.py", line 24, in <module> from rest_framework.filters import ...
2
votes
1answer
23 views

How to build a Serializer for a Normalized DataBase

Maybe my question has already been answered, but I could not find anything. Lets say that Im building a stock inventory system using Django + Django REST for the backend. To supply this I have this ...
1
vote
2answers
24 views

Django Rest Framework - Query for exact match on two fields in a mapping table

I'm using DRF and trying to search a mapping table for exact matches so I can update that record. I have the following tables: site - id - location - address circuit - id - name - ref sitecircuits ...
1
vote
1answer
25 views

Action decorator kwargs not passed on when retrieving the view with “as_view” method on a ViewSet

In one app, I have the following ViewSet: class MyViewSet(MyGenericViewSet, ListModelMixin): queryset = MyModel.objects.all() serializer_class = MyModelSerializer @action(detail=False, ...
-1
votes
0answers
22 views

Django, crear token persistente para dispositivos móviles [on hold]

Desde Django como backend, quiero crear un token que expire normalmente como trabaja JWT pero cuando las peticiones sean de un dispositivo movil, que el token no caduque, alguien tiene alguna idea?
0
votes
0answers
23 views

Django Rest Framework Pagination: Cleaner way to return the page containing the requested data

I have a CustomPagination class that can search for a given post data and return the page containing that data. This does work. However, when dealing with tons of data, this might cause performance ...
0
votes
0answers
33 views

Process received data from python requests library to show it in template

i am try to get live data from Raspberry pi and showing it to my django template. i could send data by 'requests' library and receiv it by Django REST. but the problem is in my django for example i ...
1
vote
3answers
37 views

limit django fields queried in sql call to database by queryset

I have a table with a blob and would like to exclude it from being in the sql call to the database unless specifically called for. Out of the box django includes everything in the queryset. So far ...
0
votes
0answers
8 views

Change model value with AJAX put method - Django-rest-framework

I have to change and save value for my model from old value to the new one in var input_val = span.siblings('input').val();. User clicks an icon to edit a value, then he accepted this value clicking ...
1
vote
1answer
34 views

Django (DRF) fails to POST data to url with similar path

In my url conf I have two similar patterns: urlpatterns = [ path('chat/', views.chat), # create chat path('chat/message/', views.message), # create message ] The second path works as ...
0
votes
0answers
31 views

Matching query doesn't exist?

I am making a retweet function and it works quite smooth but I am not able to retweet my own tweets , I am able to retweet other users tweets but not mine . It shows that matching query doesn't exist. ...
0
votes
1answer
26 views

Django rest API formatting data

I am new in Django rest API. I create an API for my project where user can get data from the system via API. I serialize data and pass also but I also want to count the result and pass that value too. ...
0
votes
0answers
19 views

permission in APIView desnt work and response. but should response access deny

in below code i want add some permission but it doesn't work exactly . when i change permission to "IsAdmin" that work correctly and response "access deny" when i want get TeacherPostStatistic.but i ...
2
votes
3answers
45 views

How to handle an exception in a Django Middleware?

I have a problem with proper handling an exception in Django middleware. My exception: from rest_framework.exceptions import APIException from rest_framework.status import HTTP_403_FORBIDDEN class ...
2
votes
1answer
38 views

how to iterate over a queryset in django as i get 'int' object is not iterable

I want to get the object from a queryset accounts = group.get_external_accounts(include_sub_groups=True) try: account: StripeExternalAccount = accounts.get(account_id) except ...
0
votes
0answers
11 views

How to add multiple fields in 'lookup_field'?

I have a model which has 2 fields that will always be unique. I want to add them both to the 'lookup_field' attribute Models.py: id=models.Integerfield() slug=models.CharField(max_length=10,unique=...
3
votes
1answer
40 views

Django get a list of parents each populated with their own children

I have a pair of parent/children relation models like: class Post(models.Model): title = models.TextField(null=True) content = models.TextField(null=True) author = models.TextField(null=...
1
vote
1answer
31 views

How to create a object with nested objects in Django Rest Framework

Creating my first Django app ever here. I am having a problem with inserting my Route object. Here's my models.py: class Location(models.Model): location_id = models.AutoField(primary_key=True) ...
1
vote
0answers
23 views

How to speed up djangorestframework-bulk inserts?

I am using djangorestframework 3.9.2, and djangorestframework-bulk 0.2.1. I am trying to insert 100 objects via a REST POST, and it's submitting way too many queries. Details below. The model ...
0
votes
1answer
22 views

Validating (Django Rest Framework) Serializer Fields based on Request

I'm trying to validate a DRF serializer CharField based on the Request object. The value supplied must be checked for uniqueness against other database values, that are filtered based on the Request. ...
0
votes
1answer
23 views

Adding response for post in ModelViewset

I have to provide a DB status response (which tells if the serializer gets stored or not) after a POST request in ModelViewSet. Please help me perform that in the view. from django.shortcuts import ...
0
votes
0answers
5 views

<module> from oauth2_provider.ext.rest_framework import OAuth2Authentication ModuleNotFoundError: No module named 'oauth2_provider.ext'

i setting up facebook qauth from oauth2_provider.ext.rest_framework import OAuth2Authentication ModuleNotFoundError: No module named 'oauth2_provider.ext' after installing django-rest-framework-...
0
votes
0answers
14 views

Authenticate Third Party Callbacks

I'm hitting some third Party APIs in Django Rest. Third party provides some data through callbacks. I'm using JWT authentication for users of the site. Currently my user model is based on email and ...
0
votes
1answer
18 views

Need help for getting an output model and its corresponding view in rest_framework for django

I'm new to django and rest_framework and attempting to write an application that takes uploaded images and calculates NDVI index In models.py: InputImage model is written, that is just meant for ...
2
votes
1answer
32 views

How to serialize generic relations in DRF?

I have an Administrator model associated with three other models through generic relationship. A ='Active' D ='Disabled' status = ( (A, 'Active'), (D, 'Disabled') ) ...
1
vote
1answer
38 views

Restframework's .save() method does not save object to the Database but returns an object with new PK

I'm trying to save a validated serializer in my PostgreSQL 11.0 Database using djangorestframework. Restframework's .save() method is returning an object with a unique PK(+1 sequence) but the object ...
1
vote
2answers
18 views

Django Rest API merging delete/get/update/get methond in two class

At first you see my 4 method class in view.py: class ContactList(ListAPIView): queryset = Contact.objects.all() serializer_class = ContactSerializers # This is delete method class ...
-1
votes
0answers
13 views

Uploading Multiple files or images serializers using django

I'm trying to upload multiple files or images in one field. It's returning one image/file but not multiple objects. I've tried passing many=True in the serializer. Only one image/file is being saved ...

http://mssss.yulina-kosm.ru