django-rest-framework

request() got an unexpected keyword argument 'customer'

大憨熊 提交于 2021-01-28 20:17:20
问题 Was implementing the razorpay,got the above error. I need to create a new customer in the razorpay api. unable to get the customer as it is saying the error is unable to get customer. from django.db import models from customers.models import Customer from django.db.models.signals import post_save,pre_save import razorpay client = razorpay.Client(auth=("", "")) class BillingProfile(models.Model): customer = models.OneToOneField(Customer,null=True,blank=True) inserted = models.DateTimeField

Serialize Model from Derived (Abstract) Model

寵の児 提交于 2021-01-28 19:43:17
问题 I have the following models: class Address(models.Model): first_name = models.CharField(max_length=100) last_name = models.CharField(max_length=100) .... class Meta: abstract = True class BillingAddress(Address): is_default = models.BooleanField() ... class Meta: db_table = 'billing_address' I'm trying to build a serializer for BillingAddress: class AddressSerializer(serializers.ModelSerializer): class Meta: abstract = True model = AddressModel class BillingAddressSerializer(AddressSerializer

KeyError on relation field in Django-REST

 ̄綄美尐妖づ 提交于 2021-01-28 18:18:11
问题 I have the following models: class ProductColor(models.Model): color_title = models.CharField(max_length=50) class BasicProduct(models.Model): product_title = models.CharField(max_length=150) product_desc = models.TextField() product_price = models.FloatField(default=10.0) # Describes what colors are available for this product product_colors = models.ManyToManyField(ProductColor) class BasicCartItem(models.Model): cart_product = models.ForeignKey(BasicProduct) cart_color = models.ForeignKey

django rest framework post method giving error “Method ”POST“ not allowed”

佐手、 提交于 2021-01-28 14:41:29
问题 I am getting error 'Method "POST" not allowed' while running the api. I am new to DRF and don’t know what i am doing wrong. the GET method is working fine. I have problem with POST method. my code is given below view.py: from django.contrib.auth.models import User from django.http import Http404 from django.shortcuts import get_object_or_404 from restapp.serializers import UserSerializer from rest_framework.views import APIView from rest_framework.response import Response from rest_framework

django rest framework post method giving error “Method ”POST“ not allowed”

时间秒杀一切 提交于 2021-01-28 14:38:41
问题 I am getting error 'Method "POST" not allowed' while running the api. I am new to DRF and don’t know what i am doing wrong. the GET method is working fine. I have problem with POST method. my code is given below view.py: from django.contrib.auth.models import User from django.http import Http404 from django.shortcuts import get_object_or_404 from restapp.serializers import UserSerializer from rest_framework.views import APIView from rest_framework.response import Response from rest_framework

count the number of likes from another model Django

旧城冷巷雨未停 提交于 2021-01-28 12:15:23
问题 implementing a like model where user could like a pet. If user presses like, isLike would be true while unlike would be isLike is false Model class pet(models.Model): name = models.CharField(max_length=50) class likes(models.Model): petId = models.ForeignKey( "pet", on_delete=models.CASCADE, null=True) liker = models.ForeignKey( settings.AUTH_USER_MODEL, on_delete=models.CASCADE, null=True) isLike = models.BooleanField(default=False) class countlikes(models.Model): petId = models.ForeignKey(

Post LIST OF OBJECTS from HTML/axios with multipart/form-data to DRF multipart parser

烈酒焚心 提交于 2021-01-28 12:09:25
问题 This is my serializer: class ParentSerializer(serializers.ModelSerializer): children = ChildSerializer(many=True) # reverse FK relation ParentSerializer also has an image field, so the request has to be multipart/form-data to support both image and data in a single request. The following code/test works fine: test_data = QueryDict('', mutable=True) dictionary = { 'name': ['test'], 'children[0]': [{'key1': 'val1', 'key2': 'val2'}] } test_data.update(MultiValueDict(dictionary)) test_serializer

django.db.utils.InternalError: (1050, “Table 'django_content_type' already exists”)

北慕城南 提交于 2021-01-28 11:51:24
问题 django.db.utils.InternalError: (1050, "Table 'django_content_type' already exists") I just copied a project from my friend, when I run makemirations it runs properly. But for - python3 manage.py migrate it gives this error - Operations to perform: Apply all migrations: admin, auth, balancesheet, contenttypes, dynapp, pandl2, sessions, trialbal2 Running migrations: Applying contenttypes.0001_initial...Traceback (most recent call last): File "/home/hostbooks/django1/myproject/lib/python3.6/site

How to turn a list into a paginated JSON response for REST?

柔情痞子 提交于 2021-01-28 06:58:41
问题 I'm new to Django REST Framework and I faced a problem. I'm building a backend for a social app. The task is to return a paginated JSON response to client. In the docs I only found how to do that for model instances, but what I have is a list: [368625, 507694, 687854, 765213, 778491, 1004752, 1024781, 1303354, 1311339, 1407238, 1506842, 1530012, 1797981, 2113318, 2179297, 2312363, 2361973, 2610241, 3005224, 3252169, 3291575, 3333882, 3486264, 3860625, 3964299, 3968863, 4299124, 4907284,

Getting error : Object of type User is not JSON serializable in django python

元气小坏坏 提交于 2021-01-28 03:38:55
问题 i am new here in django python, when i am trying to get data, from 3 tables, i am getting error Object of type User is not JSON serializable , can anyone please help me why i am getting this error ? here i have added my views.py and models.py file views.py # views.py from tokenize import Token from django.contrib.auth import authenticate from rest_framework import status from rest_framework.exceptions import ValidationError from rest_framework.status import HTTP_400_BAD_REQUEST, HTTP_200_OK