Hi,

I have a puzzle here I can't solve, if you have an idea or a starting  
point, it would be very useful and appreciated.

In order to have an easy way to link to the next object and the  
previous one (with special ordering), I add to my model two Foreignkey  
pointing to self. These keys point to the previous and next object.

When it saves a new object, it set the previous and the next object  
into these field.

But when I want to delete an object, the inheritance empty all the  
model's objects.

To go around this, I override the delete() method to set to None the  
next and previous of the foreign object.

But I have a problem when I do a batch delete.

Here is a schema
object1, object2, object3

objects1.next = object2
object1.previous = object3
object2.previous = object1
object2.next = object3
object3.previous = object2
object3.nest = object1

So if I delete object 1, I expect this result:
object2.previous = object3
object2.next = object3
object3.previous = object2
object3.next = object2

Here is the steps :

1. It set the previous.next and next.previous to another object  
instead of the one that is going to be delete()
2. Save previous and next object
3. It set the object.previous and object.next to None (no inheritance  
deletion)
4. It save the current object before being delete (no inheritance  
deletion)

The problem happens on step 2.

I need to call save two times on two different object. But the second  
save doesn't work. When delete() is called on the second object, the  
previous or next field that has been change is set to none. But when I  
check in the admin the field has been correctly saved.?!?

Is someone has an idea why it do that?
Or do you have a better way I can look at?

Thank you

Francis

Code:

def remove_product_position(self, selected_product):
         #print("remove_product_position is getting called")
         try:
             previous = selected_product.previous
         except:
             previous = None

         try:
             next = selected_product.next
         except:
             next = None

         if previous == next:
             """ in condition there is only one product """
             previous_product = selected_product.previous
             previous_product.next = selected_product.next
             previous_product.previous = selected_product.previous
             previous_product.save(reorder=False)
         else:
             next_product = selected_product.next
             next_product.previous = selected_product.previous
             next_product.save(reorder=False)

             previous_product = selected_product.previous
             previous_product.next = selected_product.next
             previous_product.save(reorder=False)

         selected_product.previous = None
         selected_product.next = None
         selected_product.save(reorder=False)
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to