#19423: using formfield_overrides to set CharField size causes all admin fields 
to
use last max_length in model definition
-------------------------------------+-------------------------------------
     Reporter:  joebuyer@…           |                    Owner:  nobody
         Type:  Bug                  |                   Status:  new
    Component:  Uncategorized        |                  Version:  1.4
     Severity:  Normal               |               Resolution:
     Keywords:  max_length           |             Triage Stage:
  formfield_overrides                |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by claudep):

 * needs_better_patch:   => 0
 * needs_tests:   => 0
 * needs_docs:   => 0


Old description:

> 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.
>
> models.py:
>
> 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
>

> admin.py:
>
> 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'})},
>         }
>
> admin.site.register(Book,BookAdmin)

New description:

 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.

 models.py:
 {{{
 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
 }}}

 admin.py:
 {{{
 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'})},
         }

 admin.site.register(Book,BookAdmin)
 }}}

--

-- 
Ticket URL: <https://code.djangoproject.com/ticket/19423#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to