Re: Checking API Results before saving

2022-09-08 Thread Toshar Saini
You can design a serializer for validate api data firstly you will pass data in serializer and after validate serializer you will save to model Pseducode : res = requests.post(url+some_endpoint, data) serializer = demoserializer(res.data) if serializer.is_valid(): model.objects.create(id =

Re: Checking API Results before saving

2022-09-02 Thread lone...@gmail.com
I have been working on this issue. Here is what I have so far. My Model and pre_save information: class walmart_query_history(models.Model): storeNumber = models.CharField(max_length=10)

Re: Checking API Results before saving

2022-09-02 Thread lone...@gmail.com
Ok, I have a CreateView. The process I have now is: blank form is created by CreateView After I submit the data to the form, I have a post_save that calls a function that queries the API based on the values entered in the form. When and how do I call the serializer during this process? On

Re: Checking API Results before saving

2022-09-02 Thread Ammar Mohammed
Hello , You can design a serializer for each api endpoint and use it in your view to validate your data like validating forms data : Pseducode : res = requests.post(url+some_endpoint, data) endpoint_serializer.validate(res.data) if serializer.is_valid(): #do your stuff else : #do

Checking API Results before saving

2022-09-01 Thread lone...@gmail.com
Hello all, I am sending an GET request to an external API and I would like to validate the response before I save it to my model. How do I do this? Thank you. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this