On Mon, Dec 8, 2008 at 12:52 PM, cyberjack <[EMAIL PROTECTED]> wrote:

>
> Thanks for the idea Karen,
>
>  What's the right mechanism for passing the queryset back into the
> form? I don't see an example in the docs.
>

Just pass the queryset= parm into formset creation during post as you do
during GET:

formset = ReportFormSet(request.POST, request.FILES, queryset=reports)

As I mentioned in ticket #9758, I do not know if this is really what's
intended to be required when using model formsets, but it is a way to make
the post data get matched up properly with existing DB instances.

Karen










>
> Thanks!
>
> -Josh
>
> On Dec 4, 4:10 pm, "Karen Tracey" <[EMAIL PROTECTED]> wrote:
> > On Thu, Dec 4, 2008 at 2:12 AM, cyberjack <[EMAIL PROTECTED]> wrote:
> >
> > > Hi,
> >
> > >  I haven't been able to solve this problem, but have made some
> > > progress:
> >
> > > It's definitely *not* bug 9039. I've download the tests from that
> > > ticket and confirmed the fix was included in 1.0.2 final.
> >
> > > The problem is related to using querysets with formset_factory.  Ie,
> > > if I include a queryset filter, then I see this error. If I don't
> > > include a queryset, and thus edit all status reports, I don't see the
> > > error.
> >
> > > Lastly, I've simplified my code producing the problem:
> >
> > > my model:
> >
> > > class StatusReport(models.Model):
> > >   vehicle       = models.IntegerField()
> > >   report_date   = models.DateField()
> > >   status        = models.CharField(max_length=10)
> >
> > > and my view:
> >
> > > def detail(request, vehicle_id):
> > >    limited_reports = StatusReport.objects.filter(vehicle=vehicle_id)
> >
> > >    StatusFormSet = modelformset_factory(StatusReport, extra=0)
> > >    if request.method == 'POST':
> > >        formset = StatusFormSet(request.POST)
> > >         if formset.is_valid():
> > >            formset.save()
> > >     else:
> > >        # with error
> > >        #formset = StatusFormSet(queryset=limited_reports)
> > >        # without error
> > >        formset = StatusFormSet()
> > >    return render_to_response('manage_articles.html',
> > >                              {'formset': formset,
> > >                               'vehicle_id': vehicle_id})
> >
> > > Is this a bug in Django? If so, what should I include in the bug
> > > report?
> >
> > I think the bug is that you need to pass the queryset parameter when you
> are
> > dealing with a POST (if you've specified it on the GET) so that the
> posted
> > data can be matched up to the existing model instances.  Otherwise I
> think
> > it will be trying to validate and save as all new instances, and I think
> the
> > error message is saying you wind up with duplicate primary key ids when
> you
> > try that (though I will say that error message might could use some
> > improvement).
> >
> > Karen
> >
>

--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to