Created
April 11, 2011 11:00
-
-
Save diox/913360 to your computer and use it in GitHub Desktop.
Revisions
-
diox created this gist
Apr 11, 2011 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,23 @@ from django.db import models class Foo(models.Model): bar = models.PositiveSmallIntegerField(default=1) class Meta: ordering = ['bar'] class Child(Foo): barchild = models.PositiveSmallIntegerField(default=1) >>> str(Child.objects.order_by('pk').query) 'SELECT "test_pk_foo"."id", "test_pk_foo"."bar", "test_pk_child"."foo_ptr_id", "test_pk_child"."barchild" FROM "test_pk_child" INNER JOIN "test_pk_foo" ON ("test_pk_child"."foo_ptr_id" = "test_pk_foo"."id") ORDER BY "test_pk_foo"."bar" ASC' # order_by('pk') doesn't do anything, the default ordering is used instead! (Tested with # sqlite3 and postgresql_psycopg2 engines) >>> str(Child.objects.order_by('id').query) 'SELECT "test_pk_foo"."id", "test_pk_foo"."bar", "test_pk_child"."foo_ptr_id", "test_pk_child"."barchild" FROM "test_pk_child" INNER JOIN "test_pk_foo" ON ("test_pk_child"."foo_ptr_id" = "test_pk_foo"."id") ORDER BY "test_pk_child"."foo_ptr_id" ASC' # order_by('id') works. # Note that removing the default ordering in the parent Model also fixes the bug.