You won't see errors because you haven't included them in your
template. Either render the whole form with {{ form.as_p }} - which
will render the errors as well - or for each field include a reference
to that field's errors - {{ form.fieldname.errors }} - plus
{{ form.non_field_errors }} at the top of the form
If you've got a non-blank field in your model that you don't want to
display in your form, make sure you include it in the exclude list in
the inner Meta class. Then set it the value manually in your view.
class MyForm(forms.ModelForm):
class Meta:
exclude=['pub_date']
... in the view ...
if request.method=='POST':
form = MyForm(request.POST)
if form.is_valid()
new_obj = form.save(commit=True)
new_obj.pub_date=datetime.date.today()
new_obj.save()
The square brackets in documentation are a fairly standard way of saying
that parameter is optional. To use the parameter, type it in without the
square brackets. Thus:
pub_date = models.DateTimeField('date published', auto_now_add=True)
Regards,
Malcolm
>
> I suspect I've now moved on to a problem in a new area. The thing I
> don't quite get is why adding auto_now_add to the pub_date field in
> the model broke this. Any ideas?
Because auto_now_add fields are not editable. They are automatically
given a value at creation time.
Regards,
Malcolm