On Thu, Jan 15, 2009 at 1:58 AM, Jan Bednařík <jan.bedna...@gmail.com> wrote: > > On Wed, Jan 14, 2009 at 6:51 PM, Sebastian Bauer <ad...@ugame.net.pl> wrote: >> >> Hi >> >> I think it's a bug, but maybe im wrong: >> >> >> print Categories.objects.count() >> >>0 >> new_obj = Categories.objects.create(name="test") >> instance_1 = Categories.objects.get(pk=new_obj.pk) >> instance_2 = Categories.objects.get(pk=new_obj.pk) >> >> instance_1.delete() >> print Kategorie.objects.count() >> >>0 >> instance_2.save() >> print Kategorie.objects.count() >> >>1 >> >> how orm can save second instance of the same row when its deleted? >> >> i have 2 options to solve this problem: >> >> 1. create method of Model instance to check if row exists and let users >> to handle it by own >> or >> 2. throw exception ex. models.DoesNotExist >> >> what you think about this problem? > > Hi, > > this is happening, because Django ORM is not working as what you > expect from ORM. > > In real ORM, this: > > instance_1 = Categories.objects.get(pk=new_obj.pk) > instance_2 = Categories.objects.get(pk=new_obj.pk) > > will make only one instance with two pointers on it.
No, it's just the behavior of the save method. You can perform the operations above with a single instance and still get the same result - the row is deleted and then reinserted. Ian --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com To unsubscribe from this group, send email to django-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-developers?hl=en -~----------~----~----~----~------~----~------~--~---