I have a model with a JSONField in Django. If I issue POST through the browser using Django Rest UI, the data gets entered into the model with no issues. However,when I use Python’s requests.post in my application, everything except the JSONField data stores in the model. Here is my model Here is my Serializer Here is my view Here
Tag: django-rest-framework
Django rest framework, field that is a choice or text
Is there a way to create a field which is A text field, but, with choices. that the choices are the field existing objects? And if the word passed in is not in the existing data, add it? I’ve looked across all the internet for a field like this or example of it, either in Django or the rest framework,
Invalid password format or unknown hashing algorithm in Django class based view
I want to create user by API view. But I get this problem: serializers.py views.py How can I solve this problem? Answer You should override serializer’s create() method to hash password before saving new user object. You can use set_password for this: Otherwise User.password will be stared in DB without hashing which is not secure. Also you can use create_user
Proper usage of “callable default function” in Django REST Framework (DRF)
Question: How can I access the serializer instance or any relevant arguments in the default callable function of DRF field? Scenario: I have a serializer configuration as below, and when I try to serialize the data as, I am gettting error as, Answer Update For DRF>=3.12, use this king of default class pass a class instance instead of function to
ImportError: Could not import ‘rest_framework_simplejwt.authentication.JWTAuthentication’
I am trying to deploy a django app on GCP but when i try to make migrations it gives me this error: ImportError: Could not import ‘rest_framework_simplejwt.authentication.JWTAuthentication’ for API setting ‘DEFAULT_AUTHENTICATION_CLASSES’. ModuleNotFoundError: No module named ‘rest_framework_simplejwt’. Settings.py requirements.txt What is it that I am missing ? UPDATE I installed rest_framework_simplejwt and now the error shifted to : No module named
Capturing values from url in post request in Django
I want to capture url values from a url into my views in a post request. My urls.py looks like below from django.urls import path from . import views as projects_views and I want to capture the value project_id in my ListCreateAPIView. Get call works fine. My views.py looks like below How can this be done? Answer Use self.kwargs[“project_id”] to
How to test authenticated POST request with Pytest in Django
I want to test an authenticated post request on an API using Pytest. This is what I am doing so far: This doesn’t work because it gives me back a 401 (Unauthorized) instead of a 200. That makes sense since the fixture is a client and not an admin client. Yet if I pass in admin_client instead of client it
cant fix error: create() takes 1 positional argument but 2 were given and cant seem to fix it
I have a django rest framework view set. I want to create an object based on data that is passed in with the post request. I have it setup right now to create new object with dummy data before it starts to take information from the request. I am getting the following error: Here is my viewset method: Answer Pass
How do I access a model’s nested one-to-many relations?
I have three models as shown below: A restaurant has many menu categories, which has many menu items. Is this the right way to lay out these relationships? What’s the most efficient way to get ALL the menu items for a given restaurant? I’m hoping there’s a more effective way than to loop across all menu categories for a given
What does format=None do in Django rest full API
Recently when I read Django rest full API document I faced this code : this code is work fine but I look for format=None and I cant find out what does it do. is any body know what is it and why its important to be? Answer The django rest framework (drf) documentation explains it here. The gist of it