#NEWLINE# @ register . filter #NEWLINE# def latest( model_or_obj , num = 5 ) : #NEWLINE# #INDENT# if isinstance ( model_or_obj , basestring ) : #NEWLINE# #INDENT# model_or_obj = get_model ( * model_or_obj . split ( '.' ) ) #NEWLINE# #UNINDENT# if isinstance ( model_or_obj , QuerySet ) : #NEWLINE# #INDENT# manager = model_or_obj #NEWLINE# model_or_obj = model_or_obj . model #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# manager = model_or_obj . _default_manager #NEWLINE# #UNINDENT# field_name = model_or_obj . _meta . pk . name #NEWLINE# for field in model_or_obj . _meta . fields : #NEWLINE# #INDENT# if isinstance ( field , ( DateTimeField , DateField ) ) : #NEWLINE# #INDENT# field_name = field . name #NEWLINE# break #NEWLINE# #UNINDENT# #UNINDENT# return manager . all ( ) . order_by ( ( '-%s' % field_name ) ) [ : num ]