In my project, I want to be able to create a list of Querysets, where each Queryset is named after the category of their respective items. I am familiar with dynamically naming variables in the context of system paths/directories (where I use f'{}
), but I'm unsure how to utilize any aspect of this in my current problem. I intended for my function to look something like this:
def productsfromcategory(categories):
productcontext = []
for category in categories:
{dynamicallynamedvariable} = Product.objects.prefetch_related("product_image").filter(category=category)[15]
print(dynamicallynamedvariable)
biglist.append(dynamicallynamedvariable)
In this, I meant for dynamicallynamedvariable
to be the name of the current category being looped through but I'm unsure as to how to implement this. Any advice on how to tackle this problem would be much appreciated.