🎯 Extremely useful function by ChatGPT

12 views
Skip to first unread message

Dean D. Babic

unread,
Oct 15, 2025, 9:12:19 AMOct 15
to Jam.py Users Mailing List
function on_field_select_value(field, lookup_item) {
    // Define which fields should trigger this filter
    const target_fields = ['album', 'genre'];

    if (target_fields.includes(field.field_name) && field.value) {
        lookup_item.set_where({ id__eq: field.value });
    }
}

This function is assuming that the ID field exists for album and genre,
and then locates the record. So it is not displaying all records, but a single one.

When we have a different ID, which is absolutely possible:

function on_field_select_value(field, lookup_item) {
    const field_map = {
        album: 'id',
        genre: 'genreid',
        artist: 'artist_id'
    };

    const target_field = field_map[field.field_name];
    if (target_field && field.value) {
        const where = {};
        where[target_field + '__eq'] = field.value;
        lookup_item.set_where(where);
    }
}


This is now on Demo/Tracks and Invoices when we click on Track, in here:
https://jampy.pythonanywhere.com/

D.
Reply all
Reply to author
Forward
0 new messages