Advertisement
msoutopico

Untitled

Mar 22nd, 2020
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.73 KB | None | 0 0
  1. def put(self, product_uuid):
  2.     data = product.parser.parse_args()
  3.    
  4.     product = productModel.find_by_product_uuid(product_uuid)
  5.  
  6.     if product == None:
  7.         product = ProductModel(product_uuid, **data)
  8.     else:
  9.         product.product_number =    data['product_number']
  10.         product.target_edit =       data['target_edit']
  11.         # not part of the model, but included for return purposes
  12.         product.comments =          data['comments']
  13.    
  14.     product.save_to_db()
  15.  
  16.     # delete all existing comments first
  17.     for existing_comment in CommentModel.find_all_by_product_uuid(product_uuid):
  18.         existing_comment.delete_from_db()
  19.  
  20.     # add new comments
  21.     for comment_data in data['comments']:
  22.         comment = CommentModel(product_uuid=product_uuid, **comment_data)
  23.         comment.save_to_db()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement