[CentralOH] (Django) ValueError: 'Book' instance needs to have a primary key value before a many-to-many relationship can be used.
kurtis.mullins at gmail.com
Wed Oct 24 17:11:28 CEST 2012
Sorry, I should have been more clear. I believe you only need one save()
before you call add() on the m2m field. I don't think you need to call it
And yeah, you can call save with commit=False to get an object instance but
I don't believe you will have a primary key until it's committed (saved).
I could be wrong though :) my brain has been all over the place coding-wise
On Oct 24, 2012 11:06 AM, <jep200404 at columbus.rr.com> wrote:
> On Wed, 24 Oct 2012 10:37:30 -0400, Kurtis Mullins <
> kurtis.mullins at gmail.com> wrote:
> > You should only need 1 save. The .add() doesn't require a save if memory
> > serves me correctly.
> I am dealing with a newly created object/row that does not yet
> have a primary key (id) until the first save.
> How were you getting a value for the primary key for the .add()
> to use? Were you using an object/row that already existed and so
> had already been saved earlier?
> On Wed, 24 Oct 2012 10:29:03 -0400, jep200404 at columbus.rr.com wrote:
> > by doing a .save() to flesh out the primary key value,
> > then doing the .add() for the ManyToManyField,
> > then doing another .save().
> I might have discovered a solution. I see something now that
> I did not see when I first looked at the code.
> Add commit=False to the first save.
>  busi = business.save(commit=False)
> from the last answer of
> CentralOH mailing list
> CentralOH at python.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the CentralOH