substitute the result for qs. pks is a set containing results of the call to the function force_text with an argument, key attribute of the o object,
pks = set ( force_text ( getattr ( o , key ) ) for o in qs )