File tree Expand file tree Collapse file tree 1 file changed +12
-6
lines changed Expand file tree Collapse file tree 1 file changed +12
-6
lines changed Original file line number Diff line number Diff line change @@ -179,12 +179,18 @@ def get_sideloadable_page(self, page):
179179
180180 def filter_related_objects (self , related_objects , lookup ):
181181 current_lookup , remaining_lookup = lookup .split ("__" , 1 ) if "__" in lookup else (lookup , None )
182- related_objects_set = {getattr (r , current_lookup ) for r in related_objects } - {None }
183- if related_objects_set and next (iter (related_objects_set )).__class__ .__name__ in [
184- "ManyRelatedManager" ,
185- "RelatedManager" ,
186- ]:
187- related_objects_set = set (chain (* [related_queryset .all () for related_queryset in related_objects_set ]))
182+ lookup_values = [getattr (r , current_lookup ) for r in related_objects if getattr (r , current_lookup ) is not None ]
183+
184+ if lookup_values :
185+ if lookup_values [0 ].__class__ .__name__ in ["ManyRelatedManager" , "RelatedManager" ]:
186+ related_objects_set = set (chain (* [related_queryset .all () for related_queryset in lookup_values ]))
187+ elif isinstance (lookup_values [0 ], list ):
188+ related_objects_set = set (chain (* [related_list for related_list in lookup_values ]))
189+ else :
190+ related_objects_set = set (lookup_values )
191+ else :
192+ related_objects_set = set ()
193+
188194 if remaining_lookup :
189195 return self .filter_related_objects (related_objects_set , remaining_lookup )
190196 return set (related_objects_set ) - {"" , None }
You can’t perform that action at this time.
0 commit comments