-2
Model
from django.db import models
from django.contrib.auth.models import User
user_agent = models.ForeignKey(User, on_delete=models.CASCADE)
def __str__(self):
return self.name
VIEWS
from django.shortcuts import render
from django.views.decorators.csrf import csrf_exempt
from rest_framework.parsers import JSONParser
from django.http.response import JsonResponse
from devedor.models import Debtor, Employees
from devedor.serializers import DebtorSerializer, EmployeesSerializer
from django.core.files.storage import default_storage
##def
@csrf_exempt
def debtorAPI(request,id=0):
if request.method=='GET':
debtors = Debtor.objects.all()
debtors_serializer = DebtorSerializer(debtors, many= True)
return JsonResponse(debtors_serializer.data, safe=False)
Serializers
from django.db.models import fields
from rest_framework import serializers
from devedor.models import Debtor, Employees
class DebtorSerializer(serializers.ModelSerializer):
class Meta:
model = Debtor
fields = (
'IdDebtor',
'name',
'id_tax',
'id_espaider',
'contabil',
'risco',
'wallet_type',
'phone_1',
'phone_2',
'phone_hot',
'phone_whatsapp',
'status_negociacao',
'user_agent',
'cpc_status',
'data_alteracao',
'observacoes_status',
'cpc_status',
'observacoes_status'
)
IS RETURNING
{
"IdDebtor": 1,
"name": "William Marques",
"id_tax": "001.255.481-29",
"id_espaider": "21223",
"contabil": "53452344.00",
"risco": "4654361.00",
"wallet_type": "MASSIFICADO PF",
"phone_1": "51991736242",
"phone_2": "51991736242",
"phone_hot": "51991736242",
"phone_whatsapp": "51991736242",
"status_negociacao": "PROPOSTA APROVADA",
**"user_agent": 3,** PRECISO RETORNAR O NOME ----
"cpc_status": "SIM",
"data_alteracao": "2021-08-24T18:51:01.235021Z",
"observacoes_status": "paris to paris"
}
]