unable to update pdf and edit category.

7 views
Skip to first unread message

Israr Hussain Rao

unread,
Mar 31, 2021, 3:46:48 AM3/31/21
to django...@googlegroups.com

my code is not giving an error but it is not performing edit action. and it uploads pdf but not shown in the html page.
*****************View.py****************
def Upload_Charter(request):
    Category_List= Category.objects.all().order_by("Category_name")# for viewing all catogories
    if request.method == 'POST':
        Remove_Category_List = request.POST.getlist('Category_Uuid_delete')
        if Remove_Category_List:
            Category.objects.filter(uuid=Remove_Category_List).delete()# removing the category
            messages.add_message(request, messages.INFO, _("Category Delete Operation Successfully Completed")) 
        else:
            pass
        action = request.POST.get('action')
        Category_Names = request.POST.getlist('Category')
        Category_Uuids = request.POST.getlist('Category_Uuid'
        for index, Category_Name in enumerate(Category_Names): 
            if Category_Name=='':
                continue
            elif not Category_Name in Remove_Category_List:
                if action=='save':
                    if  not Category.objects.filter(Category_name=Category_Name).exists():
                        Category(Category_name=Category_Name).save() # createing a new category
                elif action=='update':
                    Category.objects.filter(uuid=Category_Uuids[index]).update(Category_name=Category_Name)#UPDATE
        return redirect(reverse('Upload-Charters')) 
    return render(request, 'Upload-Charters.html',{'Category_List': Category_List})  

@login_required
def Upload_Charter_file(request):
    if request.method == 'POST' and request.FILES.get('charters_files'):
        charters_files = request.FILES.get('charters_files')
        fs = FileSystemStorage()
        filename = fs.save(charters_files.name,charters_files)
        uploaded_file_url = fs.get_available_name(filename)
    return render(request, 'Upload-Charters.html', {
             'uploaded_file_url': uploaded_file_url, 'Category_List': Category_List}) 





Reply all
Reply to author
Forward
0 new messages