在Django Admin中增加PositiveIntegerField的宽度

时间:2013-04-03 09:40:52

标签: django

在Django Admin中,为PositiveIntegerField增加输入框宽度的正确方法是什么?

更新

这些是我的文件:

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

1 个答案:

答案 0 :(得分:0)

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