<s> from django . http import HttpResponse <EOL> from . import models <EOL> def one_to_one ( request ) : <EOL> occupations = list ( models . Occupation . objects . all ( ) ) <EOL> return HttpResponse ( occupations [ <NUM_LIT:0> ] . user . id ) <EOL> def one_to_one_first ( request ) : <EOL> occupation = models . Occupation . objects . first ( ) <EOL> return HttpResponse ( occupation . user . id ) <EOL> def one_to_many ( request ) : <EOL> users = models . User . objects . all ( ) . prefetch_related ( '<STR_LIT>' ) <EOL> return HttpResponse ( users [ <NUM_LIT:0> ] . addresses . all ( ) ) <EOL> def many_to_many ( request ) : <EOL> users = list ( models . User . objects . all ( ) ) <EOL> return HttpResponse ( users [ <NUM_LIT:0> ] . hobbies . all ( ) ) <EOL> def prefetch_one_to_one ( request ) : <EOL> users = models . User . objects . all ( ) . select_related ( '<STR_LIT>' ) <EOL> return HttpResponse ( users [ <NUM_LIT:0> ] . occupation ) <EOL> def prefetch_one_to_one_unused ( request ) : <EOL> users = models . User . objects . all ( ) . prefetch_related ( '<STR_LIT>' ) <EOL> return HttpResponse ( users [ <NUM_LIT:0> ] ) <EOL> def prefetch_many_to_many ( request ) : <EOL> pets = list ( models . Pet . objects . all ( ) . prefetch_related ( '<STR_LIT:user>' ) ) <EOL> print ( models . Occupation . user ) <EOL> print ( models . User . occupation ) <EOL> return HttpResponse ( str ( pet . user ) for pet in pets ) <EOL> def prefetch_many_to_many_unused ( request ) : <EOL> users = models . User . objects . all ( ) . prefetch_related ( '<STR_LIT>' ) <EOL> return HttpResponse ( users [ <NUM_LIT:0> ] ) <EOL> def prefetch_many_to_many_single ( request ) : <EOL> hobbies = models . Hobby . objects . all ( ) . prefetch_related ( '<STR_LIT>' ) <EOL> return HttpResponse ( hobbies [ <NUM_LIT:0> ] . users . all ( ) [ <NUM_LIT:0> ] ) <EOL> def prefetch_many_to_many_no_related ( request ) : <EOL> pets = models . Pet . objects . all ( ) . prefetch_related ( '<STR_LIT>' ) <EOL> return HttpResponse ( pets [ <NUM_LIT:0> ] . allergy_set . all ( ) [ <NUM_LIT:0> ] ) <EOL> def select_one_to_one ( request ) : <EOL> users = models . User . objects . all ( ) . select_related ( '<STR_LIT>' ) <EOL> return HttpResponse ( users [ <NUM_LIT:0> ] . occupation ) <EOL> def select_one_to_one_unused ( request ) : <EOL> users = models . User . objects . all ( ) . select_related ( '<STR_LIT>' ) <EOL> return HttpResponse ( users [ <NUM_LIT:0> ] ) <EOL> def select_many_to_one ( request ) : <EOL> pets = list ( models . Pet . objects . all ( ) . select_related ( '<STR_LIT:user>' ) ) <EOL> return HttpResponse ( pets [ <NUM_LIT:0> ] . user if pets else None ) <EOL> def select_many_to_one_unused ( request ) : <EOL> pets = list ( models . Pet . objects . all ( ) . select_related ( '<STR_LIT:user>' ) ) <EOL> return HttpResponse ( pets [ <NUM_LIT:0> ] ) <EOL> def prefetch_nested ( request ) : <EOL> pets = list ( models . Pet . objects . all ( ) . select_related ( '<STR_LIT>' ) ) <EOL> return HttpResponse ( pets [ <NUM_LIT:0> ] . user . occupation ) <EOL> def prefetch_nested_unused ( request ) : <EOL> pets = list ( models . Pet . objects . all ( ) . select_related ( '<STR_LIT>' ) ) <EOL> return HttpResponse ( pets [ <NUM_LIT:0> ] ) </s>
