Opened 10 years ago

Closed 9 years ago

Last modified 9 years ago

#2972 closed defect (worksforme)

Auto population doesn't work for multiple slugs on the same model

Reported by: Archatas <aidas.bendoraitis at gmail> Owned by: Adrian Holovaty
Component: contrib.admin Version: master
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

If there is a model with more than one SlugField, then the javascript for automatic slug population is generated only for the last slug field of the model in the contributed administration.

The problem is simple and fixable in minutes.
The template tag auto_populated_field_script in django/contrib/admin/templatetags/admin_modify.py overwrites the previously collected javascript within every new iteration:

def auto_populated_field_script(auto_pop_fields, change = False):
    for field in auto_pop_fields:
         t = []
         ...
    return ''.join(t)

What has to be changed is that the t list has to be defined before iteration start:

def auto_populated_field_script(auto_pop_fields, change = False):
    t = []
    for field in auto_pop_fields:
         ...
    return ''.join(t)

Attachments (1)

auto_populated_field_script.patch (2.5 KB) - added by panta@… 9 years ago.
auto_populated_field_script patch for multiple slugs in a model

Download all attachments as: .zip

Change History (7)

comment:1 Changed 10 years ago by Adrian Holovaty

Summary: Auto population doesn't work for multiple slugs on the same model[patch] Auto population doesn't work for multiple slugs on the same model

comment:2 Changed 10 years ago by Jacob

Resolution: fixed
Status: newclosed

(In [4034]) Fixed #2972: prepopulate_from now works with multiple slugs on the same field. Thanks, Archatas.

Changed 9 years ago by panta@…

auto_populated_field_script patch for multiple slugs in a model

comment:3 Changed 9 years ago by panta@…

Resolution: fixed
Status: closedreopened
Version: 0.95SVN

In my case (r6373, konqueror on linux) it doesn't work.
I've attached a patch that solves the problem (tested both with konqueror and Firefox).
Cheers,
Marco

comment:4 Changed 9 years ago by Pete Crosier

Summary: [patch] Auto population doesn't work for multiple slugs on the same modelAuto population doesn't work for multiple slugs on the same model

comment:5 Changed 9 years ago by Jacob

Resolution: worksforme
Status: reopenedclosed

I can't reproduce this, but it worksforme in Gecko/WebKit/IE, so I'm going to assume if there's a bug it's with Konqueror.

comment:6 in reply to:  5 Changed 9 years ago by anonymous

Replying to jacob:

I can't reproduce this, but it worksforme in Gecko/WebKit/IE, so I'm going to assume if there's a bug it's with Konqueror.

I am no js expert, and I can't say if it's a bug with konqueror or django, but the patch is super-simple, and many users use konqueror, so why not simply integrate the patch and make everyone happy?

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