(field, project, type="", extras=[])
return select_field(field, choicefunc=choice_func)
Generates a SELECT field populated by data names that
    are of a certain type.
Generates a SELECT field populated by data names that
    are of a certain type.
Generates a SELECT field populated by data names that are of a certain type .
def data_field_generator(field, project, type="", extras=[]):
    """
    Generates a SELECT field populated by data names that
    are of a certain type.
    """

    query = models.Data.objects.filter(project=project).exclude(deleted=True)
    if type:
        type = type.replace(" ", '')
        query = query.filter(type__iregex=type)

    query = query.order_by("rank", "-date")

    # Create a mapping of data to id.
    datamap = dict((obj.id, obj) for obj in query)

    # The choice generator.
    def choice_func():
        choices = extras + [(d.id, d.name) for d in datamap.values()]
        return choices

    # Add the data type to the label.
    if type:
        help_text = field.get('help', '')
        type_text = f" Required data type: {type}"
        # Add a line break for the data type
        help_text = f'{help_text} {type_text}' if help_text else type_text
        # Insert new help text
        field['help'] = help_text

    # Returns a SELECT field with the choices.
    return select_field(field, choicefunc=choice_func)
def data_field_generator ( field , project , type = "" , extras = [ ] ) : query = models . Data . objects . filter ( project = project ) . exclude ( deleted = True ) if type : type = type . replace ( " " , '' ) query = query . filter ( type__iregex = type ) query = query . order_by ( "rank" , "-date" ) # Create a mapping of data to id. datamap = dict ( ( obj . id , obj ) for obj in query ) # The choice generator. def choice_func ( ) : choices = extras + [ ( d . id , d . name ) for d in datamap . values ( ) ] return choices # Add the data type to the label. if type : help_text = field . get ( 'help' , '' ) type_text = f" Required data type: {type}" # Add a line break for the data type help_text = f'{help_text} {type_text}' if help_text else type_text # Insert new help text field [ 'help' ] = help_text # Returns a SELECT field with the choices. return select_field ( field , choicefunc = choice_func )