1

This is the first time i am using REST for any web applications.

For normal get an post and i simply call the API done in Django Rest Framework.

But i am not able to think how can i deal with situations where something more needs to be done.

Suppose I have

  1. List of users in database and their product they have bought.

Now i have web form where if someone adds the user and then submit the button , then

  1. I have to get the list of items bought by that user in 5 hour window
  2. Update the row in database which says buy_succeessful to false
  3. Then again get the list of orders from the items he has bought and then update the rows with order_successful to false

Now current in my submit actions i am doing like

  1. call to api to add the user in override manual enrty table. This is simple post to that table
  2. Then after getting the sucessful tehn i again call api to list of items this user has bought using Query parameters . Then i have the list

  3. Then again i loop through the list and post to api for updating that record in datbase

and so on

I am feeling this is not right.

I have found that quite often there are some more things to do tahn just saving individual objects in database.

whats the best way to do that. DO i need to have view api for every function

user3214546
  • 6,523
  • 13
  • 51
  • 98

1 Answers1

1

Try the 3rd step of the DRF Tutorial:

http://www.django-rest-framework.org/tutorial/3-class-based-views

Here, it shows how to do a "PUT" request for updating data. And also some of the other DRF features.

Also, you can reference serializer.object which is the object instance of the django model record that you are saving to the database. This question here talks about adding extra attributes, etc... before saving to the database:

Editing django-rest-framework serializer object before save

You can also access the record post_save and there are other hooks in the framework that you can use.

Community
  • 1
  • 1
Aaron Lelevier
  • 19,850
  • 11
  • 76
  • 111