Skip to content
Advertisement

Tag: django-rest-framework

AttributeError: ‘tuple’ object has no attribute ‘model’. How to fix this error?

I’m new to Django. Please help me to solve this error. I’m not getting any solution. I tried many stackoverflow solutions and GitHub solutions but I’m not getting where the error is coming from. urls.py models.py views.py serializers.py Exception log Here is the github link of the app – Django I tried many stackoverflow solutions but I am not understanding

Prepopulate a DateTimeField in Django Rest Framework

I’m using a Django Rest Framework Serializer. Fields allow the initial parameter to be passed, which prepopulates a values in the browsable API. In the docs, the DateField is used as an example with an initial value of datetime.date.today. I would like to prepopulate a DateTimeField. However, the initial value is being ignored and I see mm/dd/yyyy, –:– — as

Django View, foreign key field is killing performance

MyObjects definition: View definition: I do some calculations in my view that are irrelevant and my view takes around 3 seconds for 5000 objects if my_dict[str(my_obj.foreign_key_field)] += 1 is commented out. However, when that line uncommented, my view takes 20seconds. It must be because this field is a foreign key field as none of my other fields are foreign keys.

How to give the data to serializer with JSONField

I have model and serializer with JSONField Then,I want to set the data to serializer class, However some how serializer.is_valid() faild. I have tested two pettern data1 data2 What data should I give to this serializer? And is there any method to debug is_valid()? Answer You are giving the data in right way, but as you are updating partially, you

PUT or PUSH for modifying the existing data?

I have viewset, Which shows the view on /api/companys There is a button for POST I can add the new data from this form. Now I want to modify the existing data. I have basic questions. PUSH can modify the data? or PUT should be implemented? How PUT can be implemented for ModelViewSet? Answer Mainly for updating(modify) data using PATCH

ModuleNotFoundError: No module named ‘rest_framework’ (tried many solutions but not working)

I have encountered this error. ModuleNotFoundError: No module named ‘rest_framework’ I have a virtual environment setted up and the rest framework is installed correctly. When I run pip3.10 show djangoframework, I get My interpreter is Python 3.10.8 which is the same version and it is for the virtual environment. my VSCode shows my interpreter as Python 3.10.8 (“TESTPY”:venv) .Scriptspython.exe. I

Django Rest API from Database

I have 2 APIs from my existing project. Where One provides the latest blog posts and another one provides sorting details. The 2nd API (sorting) gives blog posts ID and an ordering number, which should be in the 1st,2nd,3rd…n position. If I filter in the first API with that given ID I can get the blog post details. How can

Advertisement