Opened 8 years ago

Last modified 8 years ago

#19423 closed Bug

using formfield_overrides to set CharField size causes all admin fields to use last max_length in model definition — at Initial Version

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


Here's my example. See how title and ISBN are defined with max_length of 100 and 14. The override cause both fields to have max_length of 14 with respect to a user who is editing in the change form - a 15th character cannot be inserted into the title field.

from django.db import models

class Book(models.Model):

title = models.CharField(max_length=100,blank=True, null=True)
ISBN13 = models.CharField(max_length=14,unique=True)
def unicode(self):

return self.title

from django.contrib import admin
from django.db import models
from django.forms import TextInput
from books.models import Book

class BookAdmin(admin.ModelAdmin):

formfield_overrides = {

# Django enforces maximum field length of 14 onto 'title' field when user is editing in the change form
models.CharField: {'widget': TextInput(attrs={'size':'30'})},

Change History (0)

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