Example #1
0
def commonDel(request):
    """models to delete"""
    if request.method == "POST":
        str_model = request.POST.get('model')
        id = request.POST.get('id')
        obj_content = ContentType.objects.get(model=str_model)
        if str_model == 'pictype':          # delete pic
            img = []
            img += MyPic.objects.filter(type=id).values_list('img', flat=True)
            img.append(PicType.objects.get(pk=id).img)
            keys = Pic.objects.filter(id__in=img).values_list('key', flat=True)
            # delete remote file
            qn = SuperQiniu(keys)
            qn.delMoreFiles()
            # delete models
            MyPic.objects.filter(type=id).delete()
        if str_model == 'pic':
            MyPic.objects.filter(img=id).delete()
            PicType.objects.filter(img=id).delete()
            picture = Pic.objects.get(pk=id)
            qn = SuperQiniu(picture.key)
            qn.delFile()        # 删除远程图片
        if str_model == 'wikitype':         # delete wiki
            Wiki.objects.filter(category=id).delete()

        obj = obj_content.get_object_for_this_type(pk=id).delete()
        return HttpResponse('ok')
Example #2
0
def commonDel(request):
    """models to delete"""
    if request.method == "POST":
        str_model = request.POST.get('model')
        id = request.POST.get('id')
        obj_content = ContentType.objects.get(model=str_model)
        if str_model == 'pictype':  # delete pic
            img = []
            img += MyPic.objects.filter(type=id).values_list('img', flat=True)
            img.append(PicType.objects.get(pk=id).img)
            keys = Pic.objects.filter(id__in=img).values_list('key', flat=True)
            # delete remote file
            qn = SuperQiniu(keys)
            qn.delMoreFiles()
            # delete models
            MyPic.objects.filter(type=id).delete()
        if str_model == 'pic':
            MyPic.objects.filter(img=id).delete()
            PicType.objects.filter(img=id).delete()
            picture = Pic.objects.get(pk=id)
            qn = SuperQiniu(picture.key)
            qn.delFile()  # 删除远程图片
        if str_model == 'wikitype':  # delete wiki
            Wiki.objects.filter(category=id).delete()

        obj = obj_content.get_object_for_this_type(pk=id).delete()
        return HttpResponse('ok')