我的模型中有一个DecimalField,我想在管理界面中显示一个位于该字段右侧的单位,如下所示:
我认为如果我在字段中添加com.android.dex.DexException: Too many classes in --main-dex-list, main dex capacity exceeded
,则会显示在字段下方。有没有办法指定它显示在右边?
答案 0 :(得分:3)
您可以使用help_text
中的forms
来处理它,覆盖表单中的字段,例如css
。
from django.db import models
from django.contrib import admin
from django import forms
from your.models import Post
class PostForm(forms.ModelForm):
ethanol = forms.FloatField(
label='This is Ethanol',
max_value=10,
min_value=0,
widget=forms.NumberInput(
attrs={
'class': 'whatever',
'style': 'position:relative'
}
),
help_text='<span style="position:absolute;right:0">g/mL</span>'
)
class Meta:
model = Post
fields = '__all__'
class PostAdmin(admin.ModelAdmin):
form = PostForm
list_display = ['ethanol', 'id']
admin.site.register(Post, PostAdmin)