Hi everyone,

I have items that have an order. This function is supposed to move items 
up (swapping the order with the previous item) or down (...). I tried 
doing it via a transaction (as 'order' is logically unique), but on the 
first save() it fails with a ProgrammingError:

@transaction.commit_manually
def move_item_with_order(item, direction):
     second_item = None

     if direction == 'up':
         # are there items with a lower order?
         qs = item.__class__.objects.all().filter(order__lt=item.order)

         if qs.count() > 0:
             second_item = qs.order_by("-order")[0]

     elif direction == 'down':
         # are there items with a higher order?
         qs = item.__class__.objects.all().filter(order__gt=item.order)

         if qs.count() > 0:
             second_item = qs.order_by("order")[0]

     if second_item:
         item.order, second_item.order = second_item.order, item.order
         item.save()
         second_item.save()

     transaction.commit()

this seems like a textbook example of something where you need to start 
a transaction, and I'm not understanding what I do wrong...

Any clues?


  - bram

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