Seth, see: http://docs.djangoproject.com/en/1.3/ref/models/instances/#deleting-objects
"Issues a SQL DELETE for the object. This only deletes the object in the database; the Python instance will still be around, and will still have data in its fields." I think you will have to re-query your target object after you delete a source object. The delete() On May 3, 2:05 pm, Seth Gordon <se...@ropine.com> wrote: > I have one Django model that points to another one with a OneToOneField, > sort of like this: > > class Target(models.model): > # stuff > > class Source(models.Model): > target = models.OneToOneField(Target) > > Sometimes, given an object that is an instance of Target, I want to > navigate to its Source and delete that: > > try: > some_target.source.delete() > except ObjectDoesNotExist: > ## nothing to delete! > pass > > But this doesn't work: some_target.source will still exist after the > delete() operation has been performed. If I try "some_target.source = > None", I get an exception, complaining that Target.source does not allow > null values. Calling save() and clean_fields() at strategic moments > doesn't seem to work, either. > > What does seem to work is reloading the Target object: > > try: > some_target.source.delete() > some_target = Target.objects.get(pk=some_target.id) > except Source.DoesNotExist: > ## nothing to delete! > pass > > Is this a bug in Django, or am I misunderstanding how related or cached > objects are supposed to work? > > This is Django 1.2.3, Python 2.6.5, PostgreSQL 8.4.7, all running on > Ubuntu Linux 10.04. -- 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 django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.