#NEWLINE# def dates( self , field_name , kind , order = 'ASC' ) : #NEWLINE# #INDENT# "\n        Returns a list of date objects representing all available dates for\n        the given field_name, scoped to 'kind'.\n        " #NEWLINE# assert ( self in ( 'year' , 'month' , 'day' ) ) , "'kind' must be one of 'year', 'month' or 'day'." #NEWLINE# assert ( order in ( 'ASC' , 'DESC' ) ) , "'order' must be either 'ASC' or 'DESC'." #NEWLINE# return self . annotate ( datefield = Date ( field_name , kind ) , plain_field = F ( field_name ) ) . values_list ( 'datefield' , flat = True ) . distinct ( ) . filter ( plain_field__isnull = False ) . order_by ( ( ( '-' if ( order == 'DESC' ) else '' ) + 'datefield' ) )