Is there any Pythonic way to manipulate Dictionaries to follow DRY philosophy in Django?

I have got dictionary set of required queries as shown below:

[{'primary_attribute__name': 'Color', 'primary_attr_values__name': 'Red'}, {'primary_attribute__name': 'Color', 'primary_attr_values__name': 'Green'}]

Now I want to access/show dictionary element on template or views on following way:
Color : Red
and so on…

How can I do this?

To clarify, are you saying that you want to convert this dictionary:
{'primary_attribute__name': 'Color', 'primary_attr_values__name': 'Red'}

Into a query that looks something like this?:
SomeModel.objects.filter(primary_attribute__name='Color', primary_attr_values__name='Red')

If not, what are you trying to achieve here? It’s not clear what the desired end result is.

no, Actually it

[{'primary_attribute__name': 'Color', 'primary_attr_values__name': 'Red'}, {'primary_attribute__name': 'Color', 'primary_attr_values__name': 'Green'}]

is the result of

primary_attribute_list = list(ProductAttribute.objects.filter('primary_attribute__name','primary_attr_values__name'))

Where primary_attribute__name will be same for respective product,but the


will be different.

On this I want to print like: Color : Red, Green, etc … on template

Now I want :

[{'primary_attribute__name': 'Color', {
                                     'primary_attr_values__name': 'Red',
                                     'primary_attr_values__name': 'Green',
                                      'primary_attr_values__name': 'Yellow'

That data structure you posted isn’t valid. You’re missing a quote after the first ‘primary_attribute__name’, and the second element isn’t a key:value pair.

[Edit: I see you corrected the quotes issue, but that still isn’t valid syntax.]