Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have few querysets that I use in every single view (>50). Is there a way to write once for all and keep the queryset result available for all views ?

def MyView(request):
company= Company.objects.get(User=request.user)
user_info= User_infos.objects.get(User= request.user)
groups= request.user.groups.values_list('name',flat = True)

I'm using those results for filtering purposes like

Product.objects.filter(Company = company)
question from:https://stackoverflow.com/questions/65936486/optimize-repeteted-queryset

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
287 views
Welcome To Ask or Share your Answers For Others

1 Answer

This can be done with caching, this can allow repeated querysets to be kept for a set amount of time and then instead of querying it will get the cached results.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...