update single model using django

Viewed 31

update single model using django: I cannot update only one field using postman. when i try to update one field, i cannot save.? It seems like model. Model doesn't have an update() method yet I cannot invoke .save() as I have a pre-save signals which messes things up. This is my model:

    class Details(models.Model):
        id = models.AutoField(primary_key=True)
        name=models.CharField(max_length=50)
        email=models.CharField(max_length=50)
        number=models.BigIntegerField()
        address=models.TextField()
        image=models.CharField(max_length=100,blank=True)
        status=models.BooleanField(default=True)

and this is my api:

    elif request.method=='PUT':
            details_data=JSONParser().parse(request)
            details=Details.objects.get(id=details_data['id'])
            details_serializer=DetailsSerializer(details,data=details_data)
            if details_serializer.is_valid():
              details_serializer.save()
              return JsonResponse("updated Successfully",safe=False)
            return JsonResponse("Failed to update",safe=False)
0 Answers
Related