Opened 6 years ago

Closed 6 years ago

Last modified 5 years ago

#14193 closed (fixed)

prepopulated_fields should concatenate fields in given order

Reported by: bmihelac Owned by: bmihelac
Component: contrib.admin Version: master
Severity: Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


When generating slug from more than one field order of fields in list should be respected.

Currently, the order in which fields are rendered in admin form affects the slug creation.

In the following example, slug would look "first_name-last_name" and I would expect "last_name-first_name".

class Person(models.Model):
    first_name = models.CharField(_('First name'), max_length=80)
    last_name = models.CharField(_('Last name'), max_length=80)

class PersonAdmin(admin.ModelAdmin):
    prepopulated_fields = {"slug": ('last_name', 'first_name')}

To change the order, one can swap the order in Person model, but it would be more naturally if populate would respect order that is given with tuple.

If you agree, I can make a patch for this.

Attachments (1)

0001-Fix-for-14193-respect-given-order-when-creating-prep.patch (5.7 KB) - added by bmihelac 6 years ago.

Download all attachments as: .zip

Change History (8)

comment:1 Changed 6 years ago by lukeplant

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

Agreed, patch gladly accepted! If this is just a javascript problem, you don't have to add tests since we don't have other tests for javascript functionality.

comment:2 Changed 6 years ago by bmihelac

  • Owner changed from nobody to bmihelac
  • Status changed from new to assigned

comment:3 Changed 6 years ago by bmihelac

  • Has patch set

Because jQuery selected objects always return elements in document order I choosed to update prepopulate javascript function so it expects dependencies as array of field id's and not jQuery object.
Please let me know if you agree with this decission.

Patch is tested with regular admin forms, stacked and tabular formsets.

comment:4 Changed 6 years ago by mk

  • Triage Stage changed from Accepted to Ready for checkin

comment:5 Changed 6 years ago by andrewgodwin

  • Resolution set to fixed
  • Status changed from assigned to closed

(In [14122]) Fixed #14193: prepopulated_fields javascript now concatenates in correct order. Thanks to bmihelac for the patch.

comment:6 Changed 6 years ago by andrewgodwin

(In [14123]) [1.2.X] Fixed #14193: prepopulated_fields javascript now concatenates in correct order. Thanks to bmihelac for the patch.

Backport of [14122] from trunk

comment:7 Changed 5 years ago by jacob

  • milestone 1.3 deleted

Milestone 1.3 deleted

Note: See TracTickets for help on using tickets.
Back to Top