将查询集存储在本地存储中

Store queryset in local storage

提问人:Varad Shinde 提问时间:11/12/2023 更新时间:11/12/2023 访问量:10

问:

我想存储表单提交的查询集结果,以便在再次访问后恢复其状态。我尝试使用,localStorage,cache,但它们都出现了问题,即 valus 不是将数据保存为查询集,而是存储为字符串。

views.py

def Elective_HD_list(request):
  
    try:
        Elective_list= localStorage.getItem("list_HD")

        form=ElectiveForm_HD()
    except AttributeError:
        Elective_list=[]
        form=ElectiveForm_HD()
    if request.method=="POST":
        form=ElectiveForm_HD(request.POST or None)
        
        if form.is_valid():
               
                Elective_list=form.cleaned_data['Elective_ID']
                request.session['form_data'] = Elective_list
                localStorage.setItem("list_HD",Elective_list) #stored as a string instead of query

               
               
               
    return render(request,"homepage/Elective_HD_list.html",{"form":form,"elective_list":Elective_list})```



Is there a way to store queryset which I can access in further iterations as needed
缓存 django-forms 本地存储 pickle

评论


答: 暂无答案