Try setting the primary_key option as True.

>From http://www.djangoproject.com/documentation/models/one_to_one/:

class Restaurant(models.Model):
    place = models.OneToOneField(Place, primary_key=True)

# Delete the restaurant; the waiter should also be removed
>>> r = Restaurant.objects.get(pk=1)
>>> r.delete()

Cheers.

--
Rui


On Wed, Jul 9, 2008 at 1:12 PM, alex finn <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> I'm new to django and was trying to play around OneToOne mapping (a
> very powerful feature in my mind) and found one possible issue.
>
> I created two models: Person and Profile, where Profile is mapped to
> Person with OneToOne profile field in the Person class. So now when I
> create a Person, I need to create a Profile instance in advance which
> is fine. But what I noticed is that when I delete Person instance the
> associated Profile instance is not deleted automatically which is what
> I would expect as it is OneToOne mapping.
>
> Ok, I can override Person's delete method which allows me to handle
> this and delete the associated model instance.
>
> But now when I need to delete all the Person instances in the
> collection (i.e. Person.objects.all().delete()), Person's delete
> method won't be involved and thus all the Profile instance will stay
> alive. Is this something expected or is this a bug? Does anybody have
> an experience of dealing with such issue?
>
> Thanks,
> Alex.
> >
>

--~--~---------~--~----~------------~-------~--~----~
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