M
M
MaxEpt2019-07-30 15:10:06
Django
MaxEpt, 2019-07-30 15:10:06

How to delete records after request in django?

Hello everyone, how in django, after receiving the data, delete them from the table?
If I do as in the code (commented out part), then an empty array is returned.

class CrmReceiptView(APIView):
    def get(self, request):
        if 'kkt_id' not in request.GET:
            return Response({'message': 'Не указан ID кассы'}, status=status.HTTP_400_BAD_REQUEST)
        else:
            receipts = CrmReceipt.objects.filter(kkt=CrmKKT.objects.get(id=request.GET['kkt_id']))
            serializer = CrmReceiptSerializer(receipts, many=True)
            #receipts.delete()            
            return Response(serializer.data)

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
alternativshik, 2019-07-30
@MaxEpt

what do you expect to see there if you deleted them?

Y
Yura Khlyan, 2019-07-30
@MAGistr_MTM

Write serializer.data to a variable and then delete receipts

J
JRazor, 2019-07-31
@JRazor

CrmReceipt.objects.filter(kkt=CrmKKT.objects.get(id=request.GET['kkt_id']))

spelled like
One request less. But this is so, by the way.

_
_, 2019-08-01
@mrxor

receipts = list(CrmReceipt.objects.filter(kkt_id=request.GET['kkt_id']))

Will force djanga to go to the database before deletion and you will get the expected result

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question