Opened 9 years ago

Closed 7 years ago

Last modified 7 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
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@… 8 years ago.
auto_populated_field_script patch for multiple slugs in a model

Download all attachments as: .zip

Change History (7)

comment:1 Changed 9 years ago by adrian

  • Summary changed from Auto population doesn't work for multiple slugs on the same model to [patch] Auto population doesn't work for multiple slugs on the same model

comment:2 Changed 9 years ago by jacob

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

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

Changed 8 years ago by panta@…

auto_populated_field_script patch for multiple slugs in a model

comment:3 Changed 8 years ago by panta@…

  • Resolution fixed deleted
  • Status changed from closed to reopened
  • Version changed from 0.95 to SVN

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 7 years ago by PJCrosier

  • Summary changed from [patch] Auto population doesn't work for multiple slugs on the same model to Auto population doesn't work for multiple slugs on the same model

comment:5 follow-up: Changed 7 years ago by jacob

  • Resolution set to worksforme
  • Status changed from reopened to closed

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 7 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