Tim,

I found this in the Django source code on Github searching for 
'formfield_overrides'. It is in a test module testing formfield_overrides 
functionality. I'm assuming you imported TextInput from forms? This should 
work to change your *admin* display. Are trying to change your Admin panel 
form or a form going out to the user?


class BandAdmin(admin.ModelAdmin):
 formfield_overrides = {
 CharField: {'widget': forms.TextInput(attrs={'size': '10'})}
 }


Regards,
Joe

On Saturday, May 11, 2019 at 2:10:06 PM UTC-5, tim042849 wrote:
>
>  2.1.5 with python 3.7.2 
>
> I have a models.py class as follows: 
> class Article(models.Model): 
>     title = models.CharField(max_length=255,) 
>          
> And I want to override the rendered default size attribute to 100 in 
> the input/text form field. 
>
> the template rendering is done as follows 
> <form method="post"> 
>     {% csrf_token %} 
>     {{ form.as_p}} 
>     <button class="btn btn-dark ml-2" type="submit">Save</button> 
> </form> 
>
> in the application admin.py I have the following: 
> class ArticleAdmin(admin.ModelAdmin): 
>     formfield_overrides = { 
>         models.CharField: {'widget': TextInput(attrs={'size': '100'}), }, 
>         } 
> # registered as 
> admin.site.register(Article, ArticleAdmin) 
>
> Sadly it appears to have no effect. 
> Viewing the rendered source, I do not see a size attribute. 
> the field is rendered as: 
> <input type="text" name="title" maxlength="255" required id="id_title"> 
>
> Have I ommited a step? 
> thanks 
> -- 
> Tim Johnson 
> http://www.tj49.com 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/97e5ce92-a476-467f-a323-a724c16c8421%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to