On Sunday, 16 September 2012 00:00:09 UTC+1, Nicolas Dubien wrote: > > Hi, > > I'm using a quite huge database with twenty thousand entries or more. At > the beginning, I used to sort it each time (.sort_by("my_field_name")) I > need the page but I saw that it took me lot of time to generate the page. > > I'm looking for a solution, that allows me to show the data without > sorting it each time I want to see it. For a instance, sorting the database > each time I add an entry or each time I add several entries could be a > solution. > Is it possible to keep the database sorted by a field without changing the > pk? > > I tried the class Meta with the argument ordering but it didn't work (even > if I flush the db). > > Yours, > -DubZzz > > Twenty thousand entries is not a "huge" database by any standards. Any db engine should be able to cope easily with many many times that. And databases are good at sorting, as long as you set them up properly.
I suspect you simply don't have an index defined for the column you're ordering on, so the db is having to manually sort each time. Usually you would define an index when creating the model, by setting db_index=True in the field options - if you add that, drop the table and re-run syncdb it should create it properly. If you need to preserve the existing data, you'll need to go into the db shell and run a CREATE INDEX manually - but again if you add the db_index flag and run `./manage.py sqlindexes my_app_name` Django will print out the SQL to run in the shell (it *won't* run it for you, you'll still need to put that command into the db shell). -- DR. -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/KTuANxnbRdwJ. 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.