我尝试为我的change_form中的标签应用完全不同的图形模板,因此我尝试使用带有自定义模板的内联来填充整个标签。
但是,现在,每当我尝试在change_form上保存一些数据时,它都不起作用:不会抛出任何错误,但数据不会被保存。我尝试在save_model()方法和clean()方法中进行更改,但无济于事。
这是代码: model.py:
class Session (models.Model):
name = models.CharField(_('name'), max_length=255)
difficulty_rate = models.IntegerField(_('difficulty_rate'), default=0)
effort_rate = models.IntegerField(_('effort_rate'), default=0)
muscular_rate = models.IntegerField(_('muscular_rate'), default=0)
admin.py:
class Sessionform(ModelForm):
class Meta:
widgets = {
'difficulty_rate': TextInput(attrs={
'data-slider-ticks':'[0,1,2,3,4,5]',
'data-slider-ticks-labels':_('["none", "", "","","","very hard"]'),
'data-slider-min':'0',
'data-slider-max':'5',
'data-slider-step':'1',}),
'effort_rate': TextInput(attrs={
'data-slider-ticks':'[0,1,2,3,4,5]',
'data-slider-ticks-labels':_('["none", "", "","","","very hard"]'),
'data-slider-min':'0',
'data-slider-max':'5',
'data-slider-step':'1',}),
'muscular_rate': TextInput(attrs={
'data-slider-ticks':'[0,1,2,3,4,5]',
'data-slider-ticks-labels':_('["none", "", "","","","very hard"]'),
'data-slider-min':'0',
'data-slider-max':'5',
'data-slider-step':'1',}),
class SessionAdmin(model.ModelAdmin):
form = SessionForm
[...]
suit_form_tabs = (('info', _('Informations')), ('model', _('Body model')))
suit_form_includes = (
('bodyoppro/admin/session/information.html', 'top', 'info'),
('bodyoppro/admin/session/muscle_body.html', 'top', 'model'),
)
information.html:
<div class="span3">
<form method="post">
<h4 align="center">Difficulty</h4>
{{ adminform.form.difficulty_rate }}
<h4 align="center">Effort</h4>
{{ adminform.form.effort_rate }}
<h4 align="center">Muscle</h4>
{{ adminform.form.muscular_rate }}
</form>
有人可以帮我一把吗?谢谢!