删除项目时列表未更新

时间:2019-04-23 21:59:08

标签: python json django

我正在为前端编写一项服务,以使用具有以下有效负载形状的更新服务。但是,当我在Skill_sub_category上添加一些技能,例如:[“ Custom,” Plumbing“]时,一切正常,但是当我尝试删除skill_sub_category上的一项技能时,列表没有得到更新。这就是我用来更新custom_item的有效负载的样子

{     “ custom_items”:     [         {             “ item_name”:“ item_custom”,             “ item_type”:1,             “测量”:“3m²”,             “ skill_sub_category”:[“自定义”,“管道”,“地毯”],             “价格”:“ 80”,             “ client”:“ OTHER”,             “ year”:“ 2019”,             “ items_source”:0,              “ id”:582}]}

我的实现看起来像这样。

   def update_items(self, request, params={}, *args, **kwargs):
    """
    :param request:
    :param params:
    :param args:
    :param kwargs:
    :return:
    """
    logger.debug("Entering the gate of the update items function")
    logger.debug("** Params are being used ** :%s" % params)
    # print(params)
    logger.debug("** Params to be updated ** :%s" % params)
    for custom in params['custom_items']:
        item_name = custom['item_name']
        item_type = str(custom['item_type'])
        item_type = ItemType.objects.get(pk=item_type)
        measurement = sanitize_data(custom['measurement'])
        # measurement = custom['measurement'].replace("", u"²")
        category = custom['skill_sub_category']
        # year = custom['year'] # Frontenders do not want us to send through the year. which makes since
        client = str(custom['client'])
        client = Client.objects.get(name=client)
        # year = PriceList.objects.get(year=year) #so we commented that
        fee = custom['price']
        items_source = custom['items_source']
        get_sp = self.staff
        logger.debug("**Fetching the Staff :%s" % get_sp)
        fetched_spp = get_sp.sp_id
        logger.debug("**Fetching the SP_id **:%s" % fetched_spp)
        try:
            item = Item.objects.get(pk=custom['id'], item_creator=fetched_spp)
        except Item.DoesNotExist:
            continue

        item.name = item_name
        item.item_type = item_type
        item.measurement = measurement
        item.items_source = items_source
        item.item_creator = fetched_spp
        item.activation_status = Item.ACTIVE
        item.is_custom_items = True
        item.save()
        price = item.price.first()
        price.client = client
        price.fee = fee
        # price.price_list = year     # And it's still working this way
        price.save()
        which_items_is_being_updated = Item.objects.get(pk=custom['id'])
        get_item_updated = which_items_is_being_updated.id
        logger.debug('**Item updated is ** :%s' % get_item_updated)
        print (which_items_is_being_updated)
        for skill in SkillSubCategory.objects.filter(name__in=category):
            skill.item.add(item)
    return {"success": True, "message": "Item updated successfuly"}

当我通过删除技能来更新skill_sub_category时,其他一切工作都很好。当需要在skill_sub_category列表中删除某项技能时,有人可以给我提示如何解决该问题吗?

0 个答案:

没有答案