Hi, book2.publisher is an attribute which was created before you deleted it. If you get book2 again from Book.objects, this attribute would not exist anymore.
I have not looked at the underlaying django source, but I guess that remove(obj) removes the attribute from obj. But clear() can't do this, since it does not have a reference to all affected objects. Thomas Margie schrieb: > It seems to me there is an inconsistency between clear() and remove > (). After a remove() I find that the related object set no longer > contains the specified object (as expected), and the specified object > also no longer points to the related set (this also is what I'd > expect). However, in the case of clear(), I find that the related > object set is now cleared out (as I'd expect), but the objects that > used to be in the set still point to the set (not what I'd expect). > Is this difference intentional? > > I also find that after exiting the shell and then going back in, now > the objects that used to be in the set no longer point to the set. > IE, the inconsistent clear behavior goes away if I exit the django > shell and then re-enter. > > class Publisher(models.Model): > name = models.CharField(max_length=100) > > class Book(models.Model): > title = models.CharField(max_length=100) > publisher = models.ForeignKey(Publisher, blank=True, null=True) > >>>> pub = Publisher.objects.create(name="pub1") >>>> book1 = pub.book_set.create(title="title1") >>>> pub.book_set.all() > [<Book: title1>] >>>> book2 = pub.book_set.create(title="title2") >>>> pub.book_set.all() > [<Book: title1>, <Book: title2>] >>>> book1.publisher > <Publisher: pub1> >>>> book2.publisher > <Publisher: pub1> > > # after using remove() to remove book1, book1.publisher is empty >>>> pub.book_set.remove(book1) >>>> book1.publisher >>>> pub.book_set.all() > [<Book: title2>] > > # Now book2 references pub. After using clear(), book2.publisher > still references pub > # This seems inconsistent with the remove() behavior above. >>>> pub.book_set.clear() >>>> book2.publisher > <Publisher: pub1> > > Any comments from those in-the-know? > > Margie > -- Thomas Guettler, http://www.thomas-guettler.de/ E-Mail: guettli (*) thomas-guettler + de --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---