def seed(): # Delete the table data. Item.delete().execute() ItemList.delete().execute() # Create the initial item list item_list = ItemList(name='Main List') item_list.save() ItemList(name='Secondary List').save() # Create items under the item list Item(name='Clean the room', item_list=item_list.id).save() Item(name='Take out the trash', item_list=item_list.id).save() Item(name='Sweep the floors', item_list=item_list.id).save()
def delete(self, item_id, action=None): """Обработка путей метода DELETE""" if not item_id or action is not None: self.error404() else: #DELETE {prefix}/{id} удаляет элемент self.set_header('Content-Type', 'application/json') try: idx = int(item_id) response = ItemList.delete(idx) self.write({'message': 'OK'}) except IndexError as err: self.set_status(404, 'Item not found') self.write({'message': 'DoesNotExist'})
def get(self): # Check if the list name is provided list_key = self.request.get('list_key') try: # Add the new list to the database grocery_list_key = ItemList.delete(list_key) # Respond with the list key self.response.set_status(201) self.response.write(grocery_list_key) except Exception as e: # Respond with the error self.response.set_status(406) self.response.write(str(e))
def delete_itemlist(self, listitem_id): """Delete itemlist with given ID""" ItemList.delete().where(ItemList.id == listitem_id).execute() return # Return nothing