Saturday, October 4, 2014

Re: help with idea

If you change how your dictionary is formatted, it can be much easier:
dicc_one = {
   
'string1': {'fieldsFK__total_one__gt': 0},
   
'string2': {'fieldsFK__total_two__gt': 0},
   
'string3': {'fieldsFK__total_three__gt': 0},
   
'string4': {'fieldsFK__total_four__gt': 0},
}
results
= {}
for k, v in dicc_one.items():
    results
[k] = Model.objects.filter(**v).count()

Otherwise, you'll need to call v.split('=') to split the fields from the values.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/18b83194-d01e-4bf2-8ff7-5990e4a5c9c5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment