On Dec 22, 4:49 am, "Greg Schwimer" <gsch...@gmail.com> wrote:
> On Sun, Dec 21, 2008 at 1:47 PM, Daniel Roseman <
>
> roseman.dan...@googlemail.com> wrote:
>
> > 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
>
> Yes, that showed me the errors.  Very helpful.
>
>
>
> > 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']
>
> So I put this in my model directly?  Under the class definition, or?

No, it's a separate class. Put it wherever you like - it's often put
in a separate forms.py, but it just needs to be somewhere you can
import it.
BTW, I missed off a line - there should be
        model=Poll
at the end, at the same indentation level as exclude.

>
> > ... 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()
>
> OK, I get that, but I'm trying to use the generic views, so is this
> applicable to my use case?

That does make it tricky. You can pass the form in as a parameter via
the URL, but that won't help with the post-save customisation.

One possibility is to 'wrap' the generic view in a custom view. James
Bennett wrote a good blog post about this a couple of years ago:
http://www.b-list.org/weblog/2006/nov/16/django-tips-get-most-out-generic-views/
--
DR.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to