Ticket #19082: better_prepopulated_fields_logic.diff

File better_prepopulated_fields_logic.diff, 1.6 KB (added by msaelices, 2 years ago)

Better autocompletion logic

  • django/contrib/admin/static/admin/js/prepopulate.js

    diff --git a/django/contrib/admin/static/admin/js/prepopulate.js b/django/contrib/admin/static/admin/js/prepopulate.js
    index 24f24f9..27a1498 100644
    a b  
    1414            field.change(function() {
    1515                field.data('_changed', true);
    1616            });
     17            if (field.val()) {
     18                field.data('_filled', true);
     19            } else {
     20                field.data('_filled', false);
     21            }
    1722
    1823            var populate = function () {
    1924                // Bail if the fields value has changed
    20                 if (field.data('_changed') == true) return;
     25                if (field.data('_changed') == true || field.data('_filled') == true) return;
    2126 
    2227                var values = [];
    2328                $.each(dependencies, function(i, field) {
  • django/contrib/admin/templatetags/admin_modify.py

    diff --git a/django/contrib/admin/templatetags/admin_modify.py b/django/contrib/admin/templatetags/admin_modify.py
    index f6ac596..65ca7af 100644
    a b def prepopulated_fields_js(context): 
    99    the prepopulated fields for both the admin form and inlines.
    1010    """
    1111    prepopulated_fields = []
    12     if context['add'] and 'adminform' in context:
     12    if 'adminform' in context:
    1313        prepopulated_fields.extend(context['adminform'].prepopulated_fields)
    1414    if 'inline_admin_formsets' in context:
    1515        for inline_admin_formset in context['inline_admin_formsets']:
Back to Top