none wrote:
> I was able to display the number of times a tag was used for a
> specific content type, however, I am not able to sort the admin list
> by this number. This is what I have so far. Any suggestions?
Sorting happens in the database, so you can only sort by a value that
exists in the database as a column on that table, or else using an
aggregate query.
If you need to sort by this field using the admin's built-in sort
toggles, you will have to actually create an IntegerField on a custom
tag model and store the updated post count in that field whenever a tag
is used.
If you can be satisfied with having the default sort be by post count,
but not be able to use sort toggles on the column header, you could
override the queryset() method of the ModelAdmin, add a post-count
aggregate to the queryset and order by it.
Carl
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAkzb/iAACgkQFRcxmeyPUXITnQCfb4re++6WxW+V2sahYaoEoBcl
GpgAn3kTj287rnWDSWQE/o5UGTcdNVjM
=ZoUI
-----END PGP SIGNATURE-----
(note - since this article was published get_query_set has changed to get_queryset)