#python #django #django-models #django-forms
#python #django #django-модели #django-forms
Вопрос:
Я использую django версии v1.8 в python 2.7
В таблице у models.py
меня есть
class Diagnosis(models.Model):
diagnosis_circumstances = models.CharField(max_length=150)
diagnosis_circumstances_date = models.DateField('Date of diagnosis',null=True,blank=True)
date_of_input= models.DateField(null=True,blank=True)
pub_date = models.DateTimeField(auto_now=True)
author = models.ForeignKey(User)
patient = models.ForeignKey(Demographic)
Когда я пытаюсь показать pub_date
поле в forms.py
подобном:
class DiagnosisForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(DiagnosisForm, self).__init__(*args, **kwargs)
self.helper=FormHelper(form=self)
self.helper.field_class = 'col-md-8'
self.helper.label_class = 'col-md-3'
# self.helper.form_class = 'forms-horizontal'
self.helper.layout = Layout(
Fieldset(
'<b>Latest update</b>',
Div(
Div('pub_date', css_class='col-md-8'),
css_class='row',
),
),
FormActions(
Submit('submit', "Save changes"),
Submit('cancel',"Cancel")
),
)
self.helper.form_tag = False
self.helper.form_show_labels = True
class Meta:
model = Diagnosis
exclude = ['patient', 'author']
list_display = ('patient', 'pub_date', 'author')
Я получаю сообщение:
WARNING:root:Could not resolve form field 'pub_date'.
Traceback (most recent call last):
File "C:Python27libsite-packagescrispy_formsutils.py", line 92, in render_f
ield
field_instance = form.fields[field]
KeyError: u'pub_date'
У вас есть какие-либо идеи, как это исправить?