<p dir="ltr">Hey,</p>
<p dir="ltr">You should only need 1 save. The .add() doesn't require a save if memory serves me correctly.</p>
<p dir="ltr">You could wrap this in a transaction. I believe django offers a transaction middle ware to automatically rollback if errors were encountered.</p>
<p dir="ltr">Good luck!</p>
<div class="gmail_quote">On Oct 24, 2012 10:30 AM, <<a href="mailto:jep200404@columbus.rr.com">jep200404@columbus.rr.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I have already solved the error in the subject line.<br>
Now, I am looking for a better solution.<br>
<br>
I have been using a ManyToManyField in Django with PostgreSQL<br>
for the first time and discovered new requirements it has.<br>
I solved the following error:<br>
<br>
ValueError: 'QcBook' instance needs to have a primary key value before a many-to-many relationship can be used.<br>
<br>
by doing a .save() to flesh out the primary key value,<br>
then doing the .add() for the ManyToManyField,<br>
then doing another .save().<br>
<br>
I'm a bit uncomfortable that between the .save()s,<br>
an incomplete record is in the database.<br>
Is there a way to get the primary key value without .save()ing<br>
so that I could have just one .save(), or am I stuck with the<br>
two .save()s and should I use a transaction around the two<br>
.saves()s?<br>
I _do_ have to worry about other processes adding to the<br>
table at the same time.<br>
<br>
_______________________________________________<br>
CentralOH mailing list<br>
<a href="mailto:CentralOH@python.org">CentralOH@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/centraloh" target="_blank">http://mail.python.org/mailman/listinfo/centraloh</a><br>
</blockquote></div>