Search code examples
pythoncssdjangodjango-adminwidth

Increase width of PositiveIntegerField in Django Admin


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;
}

Solution

  • 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',) 
            }