Opened 8 years ago

Closed 7 years ago

Last modified 6 years ago

#28205 closed Cleanup/optimization (fixed)

Document that ModelAdmin.prepopulated_fields only works on empty forms

Reported by: Ju Owned by: Botond Béres
Component: Documentation Version: 1.11
Severity: Normal Keywords: prepopulated_fields
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

ModelAdmin.prepopulated_fields auto generating works only while creating new records but not while editing them.

from django.db import models

class Item(models.Model):
    title = models.CharField(max_length=200, blank=False)
    slug = models.SlugField(max_length=200)

from django.contrib import admin
from .models import Item

class ItemAdmin(admin.ModelAdmin):
   
  prepopulated_fields = {"slug": ("title",)}

admin.site.register(Item, ItemAdmin)

Change History (8)

comment:1 by Tim Graham, 8 years ago

Component: contrib.adminDocumentation
Summary: ModelAdmin.prepopulated_fields. Auto generating does not work while editing objectDocument that ModelAdmin.prepopulated_fields only works on empty forms
Triage Stage: UnreviewedAccepted
Type: BugCleanup/optimization

That's expected behavior -- prepopulated_fields only works on empty forms. I think the idea is that slugs for existing objects shouldn't change since that could cause a URL to change. This could be documented.

comment:2 by James Seden Smith, 8 years ago

Owner: changed from nobody to James Seden Smith
Status: newassigned

comment:3 by Botond Béres, 7 years ago

Owner: changed from James Seden Smith to Botond Béres

comment:4 by Botond Béres, 7 years ago

Has patch: set

Opened a small PR which adds in the prepopulated_fields docs that it only works on empty forms.

comment:5 by Tim Graham <timograham@…>, 7 years ago

Resolution: fixed
Status: assignedclosed

In 56b364ba:

Fixed #28205 -- Doc'd that ModelAdmin.prepopulated_fields only works on add forms.

comment:6 by Tim Graham <timograham@…>, 7 years ago

In 5630f4e6:

[2.0.x] Fixed #28205 -- Doc'd that ModelAdmin.prepopulated_fields only works on add forms.

Backport of 56b364bacca0d6a6cd8fbcd93aeb49f3ad46e58c from master

comment:7 by Tim Graham <timograham@…>, 6 years ago

In 682cdf6c:

Refs #28205 -- Corrected ModelAdmin.prepopulated_fields docs regarding when they're populated.

comment:8 by Tim Graham <timograham@…>, 6 years ago

In a9d9680e:

[2.1.x] Refs #28205 -- Corrected ModelAdmin.prepopulated_fields docs regarding when they're populated.

Backport of 682cdf6cab8cb76ef1808df45631c39748052e13 from master.

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