Thank you both very much for taking the time to respond...

I got it to work using the following:
    if request.method == 'POST':

        my_data = {'type':user_type,
                   'school':current_school.id,
                   'title': request.POST['title'],
                   'first_name': request.POST['first_name'],
                   'last_name': request.POST['last_name'],
                   'phone_1': request.POST['phone_1'],
                   'phone_2': request.POST['phone_2'],
                   }
        #request.POST.update(my_data)
        form = form_class(data=my_data, files=request.FILES)
        # blah blah blah

I haven't the foggiest why this worked and the former didn't. They're
just dictionaries for goodness sake.

Anyway...

To Karen's (and your) points, I think I may be missing the boat here.

I have a Teacher class that needs to have a school. I'm setting it
above manually ('school':current_school.id) as I don't want a teacher
setting his/her OWN school (I want to do it based on the admin's
actions etc).

It seems Karen's suggestion of having school be excluded from the form
(via the class's Meta class) makes sense, but wouldn't that mean I
have to have required=False on the school field in my Teacher object
for it before the form.save will work in such a way as to save the
underlying model?

Keyton

On Jan 8, 12:38 am, Malcolm Tredinnick <malc...@pointy-stick.com>
wrote:
> On Wed, 2009-01-07 at 21:28 -0800, Keyton Weissinger wrote:
> > I have a form with the following fields (all required):
> > - first_name
> > - last_name
> > - site_id
>
> > I'd like to use a template to display only the FIRST two items to the
> > user for him to fill out:
>
> > <form action="{% url profiles_create_profile %}" method="POST">
> > {{ form.first_name }} <br/>
> > {{ form.last_name }} <br/>
> > <input type="submit" value="Submit" />
> > </form>
>
> > Then when it gets posted back to me I'd like to set the site_id based
> > on a session variable or whatever like this (from my view):
>
> >     if request.method == 'POST':
> >         my_data = {'site_id':1234}
> >         my_data.update(request.POST)
> >         form = form_class(data=my_data, files=request.FILES)
> >         if form.is_valid():
> >              process form here...
>
> > My problem is that I cannot get the form to validate. It keeps telling
> > me that site_id is not set.
>
> On the surface, that look like it should work. Which makes me suspect
> some important detail has been lost in the simplification.
>
> What does the my_data dictionary look like just before you execute the
> "form = ..." line (print it out)?
>
> Also, how is form_class specified? Finally, what is the exact error
> Django gives you? Print out form._errors, for example.
>
> Maybe somewhere in there the answer will jump out. Admittedly, all the
> clues may already be there and I'm just missing the obvious, but I can't
> see it right now.
>
> On a related note, is there any particular reason you need to have
> site_id in the form class at all? Even if it's a model form, you could
> exclude it, and add it into the model object later, couldn't you? You
> might be going about this slightly backwards by trying to force in
> site_id when it's not something that actually needs to be validated or
> form-processed.
>
> Regards,
> Malcolm
--~--~---------~--~----~------------~-------~--~----~
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