On Tue, Sep 1, 2009 at 5:52 AM, nbv4 <cp368...@ohio.edu> wrote:

>
> (Pdb) f0
> <django.forms.models.FlightForm object at 0x2303c10>
> (Pdb) f0.cleaned_data
> {'ipc': False, 'xc': 0, 'app': 0, 'pic': 0, 'cfi_checkride': False,
> 'dual_r': 0, 'date': datetime.date(2009, 9, 5), 'dual_g': 0, 'total':
> 5.5999999999999996, 'id': None, 'sic': 0, 'night_l': 0, 'holding':
> False, 'act_inst': 0, 'pilot_checkride': False, 'solo': 0,
> 'flight_review': False, 'sim_inst': 0, 'plane': <Plane: UNKNOWN>,
> 'user': <User: chris>, 'remarks': u'', 'tracking': False, 'day_l': 0,
> 'route': <Route: SD-ER>, 'person': u'', 'night': 0}
> (Pdb) f=f0.save(commit=False)
> (Pdb) f
> <Flight: 2009-09-05 -- >
> (Pdb) f.user
> *** DoesNotExist:
> (Pdb)
>
>
> What on earth could be causing this? According to cleaned_data, the
> user field is valid. Why the heck is the flight being created not
> having a valid user?
>
> The form in question is coming from a heavily customized modelformset
> where the queryset parameter is set to
> Flight.objects.get_empty_query_set(), and extra parameter is set to
> 20. So it's essentially 20 blank fields. When I use this same
> modelformset with a full queryset and extra set to 0, the formset
> saves just fine.
>
> The Flight form looks like this:
>
> ###
> class FlightForm(ModelForm):
>    user =     forms.ModelChoiceField(queryset=User.objects.all(),
> widget=HiddenInput)
>    [...]
> ###
>
> and in the view I have this:
>
> ###
>    if request.POST.get('submit'):
>        post = request.POST.copy()
>        for pk in range(0, profile.per_page):
>            if post["form-" + str(pk) + "-date"]:
>                post.update({"form-" + str(pk) + "-user": str
> (request.user.pk)})
>            else:
>                post.update({"form-" + str(pk) + "-user": u''})
>
>        formset = NewFlightFormset(post,
> queryset=Flight.objects.get_empty_query_set())
>
>        if formset.is_valid():
>            import pdb; pdb.set_trace()
>            formset.save()
> ###
>
> any ideas?


Why are you using commit=False?

--~--~---------~--~----~------------~-------~--~----~
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