help with idea

34 views
Skip to first unread message

carlos

unread,
Oct 4, 2014, 12:36:27 AM10/4/14
to django...@googlegroups.com
Hi i need have this in my views! but not working

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():
        print v
        results[k] = Model.objects.filter(v).count()  # this fail no working any idea

this error show me:

too many values to unpack

Cheers


Collin Anderson

unread,
Oct 4, 2014, 1:09:26 PM10/4/14
to django...@googlegroups.com
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.

carlos

unread,
Oct 6, 2014, 1:57:01 PM10/6/14
to django...@googlegroups.com
Collin thank so much really help me!

Cheers

--
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...@googlegroups.com.
To post to this group, send email to django...@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.

Reply all
Reply to author
Forward
0 new messages