I want to save the A
object and B
object. A
has a foreignkey to B
. B
has a OneToOneField to A
. Is there a way I can get around having to reassign the variables between each save? or perhaps there's a better way to do it?
# The models a and b were created earlier in code
# a.b = b Was already set earlier in code
# b.a = a Was already set earlier in code
with transaction.commit_on_success():
a.save() # pk created for a
b.a = a # attach a.pk to b
b.save() # pk created for b
a.b = b # attach b.pk to a
a.save() # re-save a to database