Increase width of PositiveIntegerField in Django Admin

Question:

What is proper way to increase width of input box, in Django Admin, for PositiveIntegerField ?

UPDATE

These are my files:

models.py

from django.db import models

class Report(models.Model):
    datum       = models.DateField(unique=True, help_text='Od koji je datuma izvjestaj.')
    osiguranika = models.PositiveIntegerField(help_text='Broj osiguranika.')
    /* lot of staf below*/

    def __unicode__(self):
        return str(self.datum)

forms.py

from django import forms
from hzmo_web.apps.hzmo.models import Report

class ReportForm(forms.ModelForm):
    class Meta:
        model = Report

    def __init__(self, *args, **kw):
        super(ReportForm, self).__init__(*args, **kw)
        self.fields['osiguranika'].widget.attrs['class']  = 'form-text'

css

.form-text{
    width:750px; 
    height:250px;
}
Asked By: WebOrCode

||

Answers:

models.py

class Num(models.Models):
    number   = models.PositiveIntegerField()

forms.py

class NumForm(forms.ModelForm):
    class Meta:
        model = Num

    def __init__(self, *args, **kw):
        super(NumForm, self).__init__(*args, **kw)
        self.fields['number'].widget.attrs['class']  = 'form-text'

style.css

.form-text{
    width:250px; 
        height:25px;
}

admin.py

class NumAdmin(AuditAdmin):
    form = NumForm
    list_display         = ('number', )

    class Media:
        css = {
             'all': (/style.css',) 
        }
Answered By: gangakvp

The code below can change the width of one PositiveIntegerField column with forms.NumberInput as shown below:

class ReportForm(forms.ModelForm):
    class Meta:
        widgets = {              # Here
            'osiguranika' : forms.NumberInput(attrs={
                'style': 'width:50ch'
            })
        }
 
@admin.register(Report)
class ReportAdmin(admin.ModelAdmin):
    form = ReportForm # Here

The code below can change the width of all PositiveIntegerField columns with forms.NumberInput as shown below:

@admin.register(Report)
class ReportAdmin(admin.ModelAdmin):
    formfield_overrides = {
        models.PositiveIntegerField: {
            'widget': forms.NumberInput(attrs={'style': 'width:50ch'})
        },
    }

*My answer explains other options to change the width of columns in Django Admin.

Answered By: Kai – Kazuya Ito