diff -r 548df236b2cc django/db/models/base.py
--- a/django/db/models/base.py	Sun Aug 21 18:09:08 2011 +0000
+++ b/django/db/models/base.py	Mon Aug 22 11:42:54 2011 +1000
@@ -17,6 +17,7 @@
 from django.db.models.query_utils import DeferredAttribute
 from django.db.models.deletion import Collector
 from django.db.models.options import Options
+from django.db.models.aggregates import Max
 from django.db.models import signals
 from django.db.models.loading import register_models, get_model
 from django.utils.translation import ugettext_lazy as _
@@ -24,7 +25,6 @@
 from django.utils.encoding import smart_str, force_unicode
 from django.utils.text import get_text_list, capfirst
 
-
 class ModelBase(type):
     """
     Metaclass for all models.
@@ -229,8 +229,10 @@
         opts._prepare(cls)
 
         if opts.order_with_respect_to:
-            cls.get_next_in_order = curry(cls._get_next_or_previous_in_order, is_next=True)
-            cls.get_previous_in_order = curry(cls._get_next_or_previous_in_order, is_next=False)
+            cls.get_next_in_order = curry(
+                cls._get_next_or_previous_in_order, is_next=True)
+            cls.get_previous_in_order = curry(
+                cls._get_next_or_previous_in_order, is_next=False)
             # defer creating accessors on the foreign class until we are
             # certain it has been created
             def make_foreign_order_accessors(field, model, cls):
@@ -537,8 +539,10 @@
                     # If this is a model with an order_with_respect_to
                     # autopopulate the _order field
                     field = meta.order_with_respect_to
-                    order_value = manager.using(using).filter(**{field.name: getattr(self, field.attname)}).count()
-                    self._order = order_value
+                    max_order_value = manager.using(using).filter(
+                        **{field.name: getattr(self, field.attname)}).aggregate(
+                        Max('_order'))['_order__max']
+                    self._order = (max_order_value or 0) + 1
 
                 if not pk_set:
                     if force_update:
diff -r 548df236b2cc tests/modeltests/order_with_respect_to/tests.py
--- a/tests/modeltests/order_with_respect_to/tests.py	Sun Aug 21 18:09:08 2011 +0000
+++ b/tests/modeltests/order_with_respect_to/tests.py	Mon Aug 22 11:42:54 2011 +1000
@@ -2,21 +2,21 @@
 
 from django.test import TestCase
 
-from models import Post, Question, Answer
+from .models import Post, Question, Answer
 
 
 class OrderWithRespectToTests(TestCase):
     def test_basic(self):
         q1 = Question.objects.create(text="Which Beatle starts with the letter 'R'?")
         q2 = Question.objects.create(text="What is your name?")
-        
+
         Answer.objects.create(text="John", question=q1)
         Answer.objects.create(text="Jonno", question=q2)
         Answer.objects.create(text="Paul", question=q1)
         Answer.objects.create(text="Paulo", question=q2)
         Answer.objects.create(text="George", question=q1)
         Answer.objects.create(text="Ringo", question=q1)
-        
+
         # The answers will always be ordered in the order they were inserted.
         self.assertQuerysetEqual(
             q1.answer_set.all(), [
@@ -24,7 +24,7 @@
             ],
             attrgetter("text"),
         )
-        
+
         # We can retrieve the answers related to a particular object, in the
         # order they were created, once we have a particular object.
         a1 = Answer.objects.filter(question=q1)[0]
@@ -34,20 +34,20 @@
         a4 = list(Answer.objects.filter(question=q1))[-1]
         self.assertEqual(a4.text, "Ringo")
         self.assertEqual(a4.get_previous_in_order().text, "George")
-        
+
         # Determining (and setting) the ordering for a particular item is also
         # possible.
         id_list = [o.pk for o in q1.answer_set.all()]
         self.assertEqual(a2.question.get_answer_order(), id_list)
-        
+
         a5 = Answer.objects.create(text="Number five", question=q1)
-        
+
         # It doesn't matter which answer we use to check the order, it will
         # always be the same.
         self.assertEqual(
             a2.question.get_answer_order(), a5.question.get_answer_order()
         )
-        
+
         # The ordering can be altered:
         id_list = [o.pk for o in q1.answer_set.all()]
         x = id_list.pop()
@@ -69,3 +69,27 @@
         p2_1 = Post.objects.create(title="2.1", parent=p2)
         p1_3 = Post.objects.create(title="1.3", parent=p1)
         self.assertEqual(p1.get_post_order(), [p1_1.pk, p1_2.pk, p1_3.pk])
+
+    def test_deletion_and_insertion(self):
+        """ Regression test for https://code.djangoproject.com/ticket/13296 """
+        q1 = Question.objects.create(text="Which Beatle starts with the letter 'R'?")
+        q2 = Question.objects.create(text="What is your name?")
+        a1 = Answer.objects.create(text="John", question=q1)
+        a2 = Answer.objects.create(text="Paul", question=q1)
+        a3 = Answer.objects.create(text="George", question=q1)
+        a4 = Answer.objects.create(text="Ringo", question=q1)
+        self.assertQuerysetEqual(
+            q1.answer_set.all(), ["John", "Paul", "George", "Ringo",],
+            attrgetter("text"))
+
+        # delete/move some entries
+        a2.delete()
+        a3.question = q2
+        a3.save()
+        self.assertQuerysetEqual(
+            q1.answer_set.all(), ["John", "Ringo",], attrgetter("text"))
+
+        # insert a new one and see if it lands at the end
+        a5 = Answer.objects.create(text="Guido", question=q1)
+        self.assertQuerysetEqual(
+            q1.answer_set.all(), ["John", "Ringo", "Guido"], attrgetter("text"))
