[Answered ]-How to access model with only two foreign keys?

2👍

“multiple rows were returned” is because you are using get rather then filter on either or both of the queries.

If there is only one category matching short try:

c = Category.objects.get(categoryText='short')
s = StoryCat.objects.filter(category=c)

If it is possible for there to be more then one category try something like the following:

# get just ids via values_list
cids = Category.objects.filter(categoryText='short').values_list('id', flat=True)

s = StoryCat.objects.filter(category__id__in=cids)
👤JamesO

Leave a comment