Additional field while serializing django rest framework

I am a newbie to django rest framework and have created a sample Employee model. My models.py: class Employees(models.Model): created = models.DateTimeField(auto_now_add=True) first_name =...

How do you filter a nested serializer in Django Rest Framework?

In Django Rest Framework, how do you filter a serializer when it's nested in another serializer? My filters are imposed in the DRF viewsets, but when you call a serializer from inside another...

django rest framework lookup_field through OneToOneField

https://gist.github.com/ranman/3d97ea9054c984bca75e Desired Behavior User lookup happens by the username: /api/users/randall Speaker lookup happens by the username as well:...

DRF - post to ManyToMany field

In my django app: models.py: class Destination(models.Model): name=models.CharField(max_length=30) class Ride(models.Model): driver = models.ForeignKey('auth.User',...

How to override the request method (from 'PUT' into 'POST') in Django Rest Framework

I'm coding a plugin-wrapper for provide a app to restfull, problem is the app don't process PUT request, then I get from resfull a PUT request and should change request's method into a POST...

Django Rest Framework -- no module named rest_framework

I've installed django rest framework using pip install djangorestframework yet I still get this error when I run "python3 manage.py sycndb": ImportError: No module named 'rest_framework' I'm...

Django REST Framework -- How to resolve ForeignKey to Actual Value, not index?

I have a model such as: class Job(models.Model): build = models.ForeignKey(Build, on_delete=models.PROTECT) name = models.CharField(blank=True, null=True) and a view: class...

Django Result return absolute URL's

So I have a fairly straightforward serializer in serializers.py class ScheduleSerializer(serializers.ModelSerializer): class Meta: model = FrozenSchedule fields =...

Where can I access request parameters in Django Rest Framework?

I'm using Django Rest Framework and python-requests and passing several variables through the URL as shown below. GET /api/boxobjects/?format=json&make=Prusa&model=i3&plastic=PLA HTTP/1.1 I'm...

How to decode token and get back information for djangorestframework-jwt packagefor Django

I have started using djangorestframework-jwt package instead of PyJWT , I just could not know how to decode the incoming token (I know there is verify token methode).... All I need to know is how...

Django Rest Ordering custom

I'm using django rest framework and I would like to order with a custom method. So, when I call this url for example : http://127.0.0.1:8000/api/sets/?ordering=partMissing It's possible to call a...

How can I use `django-rest-knox` with `django-rest-auth`?

I'd like to use django-rest-auth to easily make use of the registration and social auth features of django-allauth in my API. I'd also like to use django-rest-knox, as it provides a token per...

How to make HyperlinkedModelSerializer in Django Rest Framework work for foreignkeys?

I am new to Django Rest Framework and am struggling to get my serialisations to work correctly for a foreignkey relationship between two models. I have tried to reduce my setup down to be as...

Django Rest Framework - AssertionError Fix your URL conf, or set the `.lookup_field` attribute on the view correctly

I'm trying to return as single object (not a queryset) that is specific to a user without them having to specify an identifier/pk within the requested URL. Each user has an organisation FK. i.e....

django.db.migrations.exceptions.InconsistentMigrationHistory

When I run python manage.py migrate on my Django project, I get the following error: Traceback (most recent call last): File "manage.py", line 22, in...

Django (DRF): How to do case-insensitive ordering

I have an api with ?ordering=name,type I want both the name and the type to be as case-insensitive class IngredientListAPIView(ListAPIView): queryset = Ingredient.objects.all() serializer_class...

Get JSON data from POST in Django with REST Framework

I am attempting to build a REST API in Django for a Google Spreadsheet with Gspread, I'm running into a lot of issues (so if anyone happens to have a full example lying around, feel free to...

Need help understanding many and source fields in a serializer

I am currently trying to familiarize myself with DRF and while going through a tutorial these serializers were used class EmbeddedAnswerSerializer(serializers.ModelSerializer): votes =...

has_object_permission not called

I looked through similar questions on the same topic and I think I am following all the rules specified for has_object_permission. This is what I have in my settings. REST_FRAMEWORK = { ...

{ "detail": "JSON parse error - Expecting value: line 1 column 1 (char 0)" }

I am using django-restframework, I use postman POST json data to my project but I got the error like tittle, I have set raw and application/json here is the code from postman. POST...

How to modify a many-to-many collection using django rest framework

I am trying to create an endpoint where, having a User entity, I can add / remove existing Group entities to user.groups many-to-many field. But when I try to do it, django-rest-framework tries to...

Field name `username` is not valid for model `User` django rest-auth

I am trying to use Django rest_auth login with email : serializers.py: from rest_framework import serializers from users.models import User from rest_auth.serializers import...

Django: check_password returns false, even if the password was saved as hash

I am using Django==2.1.5 My goal is a simple DRF based create user and login, but instead of login with username (and pw) i want to login with the email address+pw. Therefore I saved...

How to fix UnicodeDecodeError in Django REST Framework?

I want to show ProductImageSerializer in the browsable API. But I got this error: UnicodeDecodeError at /api/product_images/ 'utf-8' codec can't decode byte 0xff in position 0: invalid start...

POST with Django Rest Framework and DataTables returns a 400 bad request

when I use the browsable API from DRF, I can POST and DELETE. Attempting to replicate this via my tradingbook.html (w/DataTables) delivers for (new/edit/delete): Bad Request: /api/trading/ with ...

Django Rest Framework AttributeError: 'str' object has no attribute 'get_default_basename'

This is my first time using viewsets and routers. When I run the server, it shows the that error. Here is the view (inside a file called api.py): class LeadViewset(viewsets.ModelViewSet): ...

How to include related model fields in elastic search document using django-elastic-search-dsl-drf

I'm using django-elasticsearch-dsl-drf, I have two models called Parent and Child where the child model has Foreign key relation with the Parent model class Parent(models.Model): name =...

Expire a token in 24 hours - django-rest-knox

I am using django-rest-knox for token authentication in my Django REST Framework app. What I want is to make the token expire only if 24 hours are passed. Is there any setting that it can make...

Django Rest Framework + psycopg2 : InterfaceError: cursor already closed

I have a problem with psycopg2. It fails to perform some queries. I have traced exceptions and it says: django.db.utils.InterfaceError: cursor already closed I have already seen some similar...

Object of type ProductImage is not JSON serializable

I am getting this error Object of type ProductImage is not JSON serializable I am trying to make model in which I can add multiple images using ManytoManyFeild().and I then I want to serialize it...