def _get_available_choices(self, queryset, value):
item = queryset.filter(pk=value).first()<EOL>if item:<EOL><INDENT>try:<EOL><INDENT>pk = getattr(item, self.chained_model_field + "<STR_LIT>")<EOL>filter = {self.chained_model_field: pk}<EOL><DEDENT>except AttributeError:<EOL><INDENT>try:  <EOL><INDENT>pks = getattr(item, self.chained_model_field).all().values_list('<STR_LIT>', flat=True)<EOL>filter = {self.chained_model_field + "<STR_LIT>": pks}<EOL><DEDENT>except AttributeError:<EOL><INDENT>try:  <EOL><INDENT>pks = getattr(item, self.chained_model_field + "<STR_LIT>").all().values_list('<STR_LIT>', flat=True)<EOL>filter = {self.chained_model_field + "<STR_LIT>": pks}<EOL><DEDENT>except AttributeError:  <EOL><INDENT>filter = {}<EOL><DEDENT><DEDENT><DEDENT>filtered = list(get_model(self.to_app_name, self.to_model_name).objects.filter(**filter).distinct())<EOL>if self.sort:<EOL><INDENT>sort_results(filtered)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>filtered = []<EOL><DEDENT>return filtered<EOL>
get possible choices for selection