I think you would either have to assign the antenna's phone:

antenna.phone = phone

or refetch the antenna from the database so Django creates the object
with the newly-created reference. The antenna you are looking at is
only coming from memory when you do antenna.phone, not from the
database. You could do it all at once like this:

antenna.phone = Phone()
antenna.save()

On Sep 14, 12:13 am, Karish <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I have two models in a one-to-one relationship: Phone and Antenna.
>
> In other words, within the Phone class I have this field:
> antenna = models.OneToOneField(Antenna, related_name='phone')
>
> What I want to do, given a specific antenna, is to delete its phone
> and add a different phone:
>
> antenna.phone.delete()
> phone = Phone()
> phone.antenna = antenna
> phone.save()
>
> Problem: after these statements, antenna.phone.id is None. I was
> expecting antenna.phone to reflect the new phone, which definitely has
> an id assigned to it after the save().
>
> Thanks!
--~--~---------~--~----~------------~-------~--~----~
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