get_object_or_404

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
from django.shortcuts import get_object_or_404
e1 = get_object_or_404(Entry, pk=3)
a1 = get_object_or_404(e1.authors, name='Fred')
# or
e1 = get_list_or_404(Entry, pk=3)
a1 = get_list_or_404(e1.authors, name='Fred')